Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 1
Default VBA help - worksheets and range questions

I am working with a workbook with 3 worksheets named "Sheet1", "wtf",
and "Sheet3." My procedure should look for data in the second sheet,
"wtf", and if found, insert a row on Sheet1 and copy the data.

One problem is that I can't seem to figure out a way to refer to the
sheet by name. A second problem is that I don't want to work with a
fixed number of rows - I would like to determine how many rows have
data in the first column and use that as a loop limit.

Any help would be appreciated. Bob.



The code I have been playing with:

Option Explicit

Sub MoveData()

Dim r As Long
Dim wtf As Worksheet
wtf = ActiveWorkbook.Sheets("wtf")

For r = 1 To 500
If (Sheets("wtf").Cells(r, 3) < "") Or (Sheet2.Cells(r, 4) < "")
Then
Sheet1.Rows(1).Insert
Sheet1.Cells(1, 1) = Sheet2.Cells(r, 3)
Sheet1.Cells(1, 2) = Sheet2.Cells(r, 4)
Sheet1.Cells(1, 3) = Sheet2.Cells(r, 3) + ", " + Sheet2.Cells(r,
4)
End If
Next



End Sub
  #2   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 27,285
Default VBA help - worksheets and range questions

Sub MoveData()

Dim r As Long
Dim wtf As Worksheet
set wtf = ActiveWorkbook.Sheets("wtf")

For r = 1 To Cells(rows.count,1).End(xlup).Row
If sh.Cells(r, 3) < "" Or Sheet2.Cells(r, 4) < "" Then
Sheet1.Rows(1).Insert
Sheet1.Cells(1, 1) = Sheet2.Cells(r, 3)
Sheet1.Cells(1, 2) = Sheet2.Cells(r, 4)
Sheet1.Cells(1, 3) = Sheet2.Cells(r, 3) + ", " + Sheet2.Cells(r,
4)
End If
Next

--
Regards,
Tom Ogilvy


End Sub
"Bob" wrote in message
m...
I am working with a workbook with 3 worksheets named "Sheet1", "wtf",
and "Sheet3." My procedure should look for data in the second sheet,
"wtf", and if found, insert a row on Sheet1 and copy the data.

One problem is that I can't seem to figure out a way to refer to the
sheet by name. A second problem is that I don't want to work with a
fixed number of rows - I would like to determine how many rows have
data in the first column and use that as a loop limit.

Any help would be appreciated. Bob.



The code I have been playing with:

Option Explicit

Sub MoveData()

Dim r As Long
Dim wtf As Worksheet
wtf = ActiveWorkbook.Sheets("wtf")

For r = 1 To 500
If (Sheets("wtf").Cells(r, 3) < "") Or (Sheet2.Cells(r, 4) < "")
Then
Sheet1.Rows(1).Insert
Sheet1.Cells(1, 1) = Sheet2.Cells(r, 3)
Sheet1.Cells(1, 2) = Sheet2.Cells(r, 4)
Sheet1.Cells(1, 3) = Sheet2.Cells(r, 3) + ", " + Sheet2.Cells(r,
4)
End If
Next



End Sub



  #3   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 3
Default VBA help - worksheets and range questions

Tom,

I will give this a try when I get into work tomorow. Thanks for the
help. I see your name quite often on the newsgroup. Without people
like you - it wouldn't work for the rest of us. I hope I can give a
little back someday.

Bob.

Tom Ogilvy wrote:
Sub MoveData()

Dim r As Long
Dim wtf As Worksheet
set wtf = ActiveWorkbook.Sheets("wtf")

For r = 1 To Cells(rows.count,1).End(xlup).Row
If sh.Cells(r, 3) < "" Or Sheet2.Cells(r, 4) < "" Then
Sheet1.Rows(1).Insert
Sheet1.Cells(1, 1) = Sheet2.Cells(r, 3)
Sheet1.Cells(1, 2) = Sheet2.Cells(r, 4)
Sheet1.Cells(1, 3) = Sheet2.Cells(r, 3) + ", " + Sheet2.Cells(r,
4)
End If
Next


  #4   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 422
Default VBA help - worksheets and range questions

Your structure **AS IS** of course
Causes your data to be copied to Sheet1 "inverted" (up-side-down).
Is that what you want?

"Bob" wrote in message
m...
I am working with a workbook with 3 worksheets named "Sheet1", "wtf",
and "Sheet3." My procedure should look for data in the second sheet,
"wtf", and if found, insert a row on Sheet1 and copy the data.

One problem is that I can't seem to figure out a way to refer to the
sheet by name. A second problem is that I don't want to work with a
fixed number of rows - I would like to determine how many rows have
data in the first column and use that as a loop limit.

Any help would be appreciated. Bob.



The code I have been playing with:

Option Explicit

Sub MoveData()

Dim r As Long
Dim wtf As Worksheet
wtf = ActiveWorkbook.Sheets("wtf")

For r = 1 To 500
If (Sheets("wtf").Cells(r, 3) < "") Or (Sheet2.Cells(r, 4) < "")
Then
Sheet1.Rows(1).Insert
Sheet1.Cells(1, 1) = Sheet2.Cells(r, 3)
Sheet1.Cells(1, 2) = Sheet2.Cells(r, 4)
Sheet1.Cells(1, 3) = Sheet2.Cells(r, 3) + ", " + Sheet2.Cells(r,
4)
End If
Next



End Sub



  #5   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 3
Default VBA help - worksheets and range questions

Yes, that is the way the existing spreadsheet is (manually) created.

Thanks for you interest!

JMay wrote:
Your structure **AS IS** of course
Causes your data to be copied to Sheet1 "inverted" (up-side-down).
Is that what you want?

"Bob" wrote in message
m...

I am working with a workbook with 3 worksheets named "Sheet1", "wtf",
and "Sheet3." My procedure should look for data in the second sheet,
"wtf", and if found, insert a row on Sheet1 and copy the data.

One problem is that I can't seem to figure out a way to refer to the
sheet by name. A second problem is that I don't want to work with a
fixed number of rows - I would like to determine how many rows have
data in the first column and use that as a loop limit.

Any help would be appreciated. Bob.



The code I have been playing with:

Option Explicit

Sub MoveData()

Dim r As Long
Dim wtf As Worksheet
wtf = ActiveWorkbook.Sheets("wtf")

For r = 1 To 500
If (Sheets("wtf").Cells(r, 3) < "") Or (Sheet2.Cells(r, 4) < "")
Then
Sheet1.Rows(1).Insert
Sheet1.Cells(1, 1) = Sheet2.Cells(r, 3)
Sheet1.Cells(1, 2) = Sheet2.Cells(r, 4)
Sheet1.Cells(1, 3) = Sheet2.Cells(r, 3) + ", " + Sheet2.Cells(r,
4)
End If
Next



End Sub







Reply
Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules

Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On


Similar Threads
Thread Thread Starter Forum Replies Last Post
2 worksheets--3 questions Anne Excel Worksheet Functions 3 April 14th 10 09:57 PM
Lookup questions cross worksheets John S Excel Discussion (Misc queries) 0 March 18th 10 05:05 PM
View Questions and Answer to questions I created Roibn Taylor Excel Discussion (Misc queries) 4 July 24th 08 12:05 AM
Multiple Named Range questions Carole O Excel Discussion (Misc queries) 3 July 3rd 07 12:12 PM
Newbie Questions - X Axis and Data Range Eli Charts and Charting in Excel 2 June 17th 05 01:54 AM


All times are GMT +1. The time now is 03:47 AM.

Powered by vBulletin® Copyright ©2000 - 2025, Jelsoft Enterprises Ltd.
Copyright ©2004-2025 ExcelBanter.
The comments are property of their posters.
 

About Us

"It's about Microsoft Excel"