Logo 
Search:

MS Office Answers

Ask Question   UnAnswered
Home » Forum » MS Office       RSS Feeds
  Question Asked By: Pedro Gilbert   on Feb 22 In MS Office Category.

  
Question Answered By: Volney Fischer   on Feb 22

Personally I got into VBA programming by purchasing a set  of "VBA Macro
Examples". It saved me a lot of time.
Regarding your question - this code will do it:

Option Explicit
Public Sub doit()
'Sheet1 is source, Sheet2, Sheet3 are targets
Dim sourceRow As Integer
Dim targetRow() As Integer
Dim sheetNum As Integer
Dim rng As Range
'there are two target sheets
ReDim targetRow(1)
'for some obscure reason the following lines return 1 when the sheets are empty!
targetRow(0) = Worksheets("Sheet2").UsedRange.Rows.Count
targetRow(1) = Worksheets("Sheet3").UsedRange.Rows.Count
sourceRow = 1
While Worksheets("sheet1").Cells(sourceRow, 1).Value <> ""
sheetNum = Worksheets("sheet1").Cells(sourceRow, 3)
Worksheets("sheet1").Rows(sourceRow).Copy
Set rng = Worksheets("sheet" & sheetNum).Rows(targetRow(sheetNum - 2))
Worksheets("sheet1").Rows(sourceRow).Copy rng

sourceRow = sourceRow + 1
targetRow(sheetNum - 2) = targetRow(sheetNum - 2) + 1
Wend
End Sub

Share: 

 

This Question has 2 more answer(s). View Complete Question Thread

 
Didn't find what you were looking for? Find more on Newbie VB help? Or get search suggestion and latest updates.


Tagged: