Flux rss
Search : in
By : Relevance Date Username
Statut : Solved

Need help in Excel Macro

zeromaim, on Tuesday July 29, 2008 03:46:06 PM
Hello Ivan,

Ive' been reading a lot of your answers and i'm quite facinated of your skill.
I need to create a macro for one of my project and it involves tranferring data (row) to specific range in another work sheet. I tried to produce a diagram but I can't seem to use it, it should help explaining my query. Anyways, i'll try it in words :)

In Sheet 1, I have a table (4 columns by 13 rows), say F11:I23. G11:G23 (2nd column) contains ID (A,B,C; randomized). Data in F11, H11, and I11 are all associated with G11.

In Sheet 2, I have another table (3 columns by 6 rows), say K11:M16. K11:M11 and K12:M12 will act as a boundary for ID "A". K13:M13 and K14:M14 will act as a boundary for ID "B". K15:M15 and K16:M16 will act as a boundary for ID "C".

Kindly help me create a macro that will identify row with ID "A" from sheet 1, copy it and insert it in sheet 2 between K11:M11 and K12:M12, pulling K12:M16 down? Same for ID "B", it will be inserted inbetween K13:M13 and K14:M14. It will therefore expand the original Sheet 2 K11:M16 to K11:M29 assuming all rows in Sheet 1 F11:I23 is not empty and has one of the IDs.

Like I said, it would've been easier if I use figures in explaining, please bear with me.

Thanks for any help you can extend.

Zero
Configuration: Windows XP
Internet Explorer 7.0
Reply to zeromaim  Report this message to moderators Go to last message

1


  • 1
    This message seems useful, vote!
  • Ce message ne vous semble pas utile, votez !
  • Report this message to moderators
Ivan-hoe, on Tuesday August 5, 2008 11:32:52 PM
Hello Zero,
in the macro below, the loop For Each Mycell ... Next Mycell "reads" the contents of each cell in the given range (G11:G23) of the first table.
Whatever the ID is, the same operations are completed : insert a row and copy out data from the first table into the second one ; this is done in the bundle With Marker .... End With .
Only the initial cell changes. Thus the idea is to start the copy from a cell (named Marker) that depends on the ID ; this is done with Select Case ... End Select
Ivan
Sub Zeromaim()
    
Dim MyCell As Range, Marker As Range
Dim LowerBoundaryForA As Range, LowerBoundaryForB As Range, LowerBoundaryForC As Range
    With Sheets("Sheet2")
        Set LowerBoundaryForA = .Range("K12")
        Set LowerBoundaryForB = .Range("K14")
        Set LowerBoundaryForC = .Range("K16")
    End With
       
    Sheets("Sheet1").Activate
    For Each MyCell In Range("G11:G23")
        
        Select Case UCase(MyCell.Value)
            Case Is = "A"
                Set Marker = LowerBoundaryForA
            Case Is = "B"
                Set Marker = LowerBoundaryForB
            Case Is = "C"
                Set Marker = LowerBoundaryForC
        End Select
        
        With Marker
            .EntireRow.Insert
            .Offset(-1, 0).Value = MyCell.Offset(0, -1).Value
            .Offset(-1, 1).Value = MyCell.Offset(0, 1).Value
            .Offset(-1, 2).Value = MyCell.Offset(0, 2).Value
        End With
        
    Next MyCell
End Sub
Reply to Ivan-hoe

2


  • This message seems useful, vote!
  • Report this message to moderators
zeromaim, on Wednesday August 6, 2008 01:42:53 PM
Hi Ivan,

Thanks again for the reply, the code was very helpful. I have some follow up question, kindly refer to the post "Need help in Excel Macro" posted by zeromaim.

Kindly insert a code that if the ID is anything other than A, B, and C, the program will just skip to evaluate the next row (no inserting). If column G11:G23 reads as A, B, C, D, E, A, B, C, etc..., the program should not copy-insert the row associated to ID D, E, and other IDs.

Thanks again and hope to hear from you soon.

Anton
Reply to zeromaim

3


  • This message seems useful, vote!
  • Report this message to moderators
zeromaim, on Wednesday August 6, 2008 01:46:51 PM
Thanks Ivan,

Follow up question :)

Kindly insert a code that if the ID is anything other than A, B, and C, the program will just skip to evaluate the next row (no inserting). If column G11:G23 reads as A, B, C, D, E, A, B, C, etc..., the program should not copy-insert the row associated to ID D, E, and other IDs.

Thanks again and hope to hear from you soon.

Anton
Reply to zeromaim

4


  • 1
    This message seems useful, vote!
  • Ce message ne vous semble pas utile, votez !
  • Report this message to moderators
Ivan-hoe, on Thursday August 7, 2008 09:23:21 AM
Sub Zeromaim()
    
Dim MyCell As Range, Marker As Range
Dim LowerBoundaryForA As Range, LowerBoundaryForB As Range, LowerBoundaryForC As Range
    With Sheets("Sheet2")
        Set LowerBoundaryForA = .Range("K12")
        Set LowerBoundaryForB = .Range("K14")
        Set LowerBoundaryForC = .Range("K16")
    End With
       
    Sheets("Sheet1").Activate
    For Each MyCell In Range("G11:G23")
        Stop
        Select Case UCase(MyCell.Value)
            Case Is = "A"
                Set Marker = LowerBoundaryForA
            Case Is = "B"
                Set Marker = LowerBoundaryForB
            Case Is = "C"
                Set Marker = LowerBoundaryForC
            Case Else
                Set Marker = Nothing
        End Select
        
        If Not Marker Is Nothing Then
            With Marker
                .EntireRow.Insert
                .Offset(-1, 0).Value = MyCell.Offset(0, -1).Value
                .Offset(-1, 1).Value = MyCell.Offset(0, 1).Value
                .Offset(-1, 2).Value = MyCell.Offset(0, 2).Value
            End With
        End If
        
    Next MyCell
End Sub
Reply to Ivan-hoe

5


  • This message seems useful, vote!
  • Report this message to moderators
 zeromaim, on Friday August 8, 2008 12:29:16 PM
Hi Ivan,

Thanks again, it's perfect.

How do I change the status of this topic to resolve? Anyone?

Anton
Reply to zeromaim

Results for

Excel Macro Help Please (Solved) Hello Everyone, I am sking for some help with an Excel macro please. I have a 1,900 hundred static HTML pages that I have converted to text for the purpose of importing to a DB via an Excel CSV file. I have everything sitting in an excel file now with... en.kioskea.net/forum/affich-11146-excel-macro-help-please
Excel Macro for deleting rows IF cells not... Hello, I need help to create a Excel macro. Basicly what I have is a sheet full with information about different departments and what I want to do is delete every row EXCEPT the rows that contain some specified values (wich i would like to enter on... en.kioskea.net/forum/affich-12620-excel-macro-for-deleting-rows-if-cells-not
Excel Macro Help please I need help with an excel macro that will take a username (string) in the first column and look at everytime that they either have an P (present), T (tardy), E (Excused), or A (absent) in a second column. They will be given 400 points if they were... en.kioskea.net/forum/affich-33502-excel-macro-help-please

Results for

To insert an image in the FAQTo insert an image in the FAQ Method Where to find images? Inserting screenshots can help to understand an explanation. Here is how to improve tips on Kioskea (FAQ). For this trick, we opted to use the site Imageshack.us. Note:... en.kioskea.net/faq/sujet-67-to-insert-an-image-in-the-faq
How to open/read a .RBS file!How to open/read a .RBS file! RBS is a file extension describing Rebirth files Song files. It is a common error associated with many file extension errors. This method allows skip over programs that are not recognized and continue process. If... en.kioskea.net/faq/sujet-379-how-to-open-read-a-rbs-file

Results for

Excel MacroI need help with an excel macro that will take a username (string) in the first column and look at everytime that they either have an P (present), T (tardy), E (Excused), or A (absent) in a second column. They will be given 400 points if they were... en.kioskea.net/forum/affich-33540-excel-macro
Excel Macro Help neededI need help with an excel macro that will take a username (string) in the first column and look at everytime that they either have an P (present), T (tardy), E (Excused), or A (absent) in a second column. They will be given 400 points if they were... en.kioskea.net/forum/affich-33099-excel-macro-help-needed
Error In ExcelHello, I recently wrote a fairly complex Excel Macro and have been trying just to work some of the bugs out of it for the past couple weeks. The most recent problems that i've run into is that when it is loaded on to the computer for a while it... en.kioskea.net/forum/affich-20216-error-in-excel

Results for

Spreadsheets - The Excel Interface Microsoft Excel is the spreadsheet in the Microsoft Office office suite. To start it, simply click on the appropriate icon in the Start menu (in Windows) or click on an Excel file (that has an .xls file extension). A Excel document is called a file... en.kioskea.net/tableur/tabinterface.php3
Email - Rules for proper email use Netiquette (a contraction of the words "Net" and "etiquette") refers to the set of rules governing correct behaviour on the Internet, in order to respect others and be respected in turn. They serve as guidelines for civility and proper conduct, so... en.kioskea.net/courrier-electronique/regles-bon-usage-messagerie.php3
Spreadsheets - Cell Selection Spreadsheets are powerful tools for working with data. However, to work with data, it is necessary to have tools to rapidly choose the required cells. An entire line can be chosen by clicking directly on the line header: It is also possible to choose... en.kioskea.net/tableur/tabcellselect-1.php3