Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.worksheet.functions
tjb
 
Posts: n/a
Default stopping code from looping

How do I modify the code below to stop running on each row with data until it
hits a blank row? I want to use a command button to execute for one row of
data only. This is a follow up to a post from Dave Petersen (he wrote the
code below) last week. Thanks all!

Private Sub Merge_Click()

Dim fWks As Worksheet
Dim tWks As Worksheet

Dim fCol As Variant
Dim tAddr As Variant

Dim iRow As Long
Dim FirstRow As Long
Dim LastRow As Long
Dim iCtr As Long

fCol = Array("a", "b", "c", "d", "e", "f", "g", "h", "i", "k", "l", "m",
"o", "p")
tAddr = Array("a1", "b1", "d12", "e13", _
"c5", "a18", "a15", "c12", "f3", "f4", _
"f17", "g9", "e1", "e2")

If UBound(fCol) < UBound(tAddr) Then
MsgBox "Design error--Not same number of columns/cells)"
End If

Set fWks = Worksheets("Entry")
Set tWks = Worksheets("Form")

With fWks
FirstRow = 2
LastRow = .Cells(.Rows.Count, "A").End(xlUp).Row

For iRow = FirstRow To LastRow
If IsEmpty(.Cells(iRow, "A")) Then
'skip this row
Else
For iCtr = LBound(fCol) To UBound(fCol)
tWks.Range(tAddr(iCtr)).Value _
= .Cells(iRow, fCol(iCtr)).Value
Next iCtr
tWks.PrintOut preview:=True
End If
Next iRow
End With

End Sub

  #2   Report Post  
Posted to microsoft.public.excel.worksheet.functions
Dave Peterson
 
Posts: n/a
Default stopping code from looping

Based on the location of the activecell?

If yes, you could cheat and just change this portion:

FirstRow = 2
LastRow = .Cells(.Rows.Count, "A").End(xlUp).Row

becomes

FirstRow = activecell.row
LastRow = activecell.row
'or even
'Lastrow = firstrow

tjb wrote:

How do I modify the code below to stop running on each row with data until it
hits a blank row? I want to use a command button to execute for one row of
data only. This is a follow up to a post from Dave Petersen (he wrote the
code below) last week. Thanks all!

Private Sub Merge_Click()

Dim fWks As Worksheet
Dim tWks As Worksheet

Dim fCol As Variant
Dim tAddr As Variant

Dim iRow As Long
Dim FirstRow As Long
Dim LastRow As Long
Dim iCtr As Long

fCol = Array("a", "b", "c", "d", "e", "f", "g", "h", "i", "k", "l", "m",
"o", "p")
tAddr = Array("a1", "b1", "d12", "e13", _
"c5", "a18", "a15", "c12", "f3", "f4", _
"f17", "g9", "e1", "e2")

If UBound(fCol) < UBound(tAddr) Then
MsgBox "Design error--Not same number of columns/cells)"
End If

Set fWks = Worksheets("Entry")
Set tWks = Worksheets("Form")

With fWks
FirstRow = 2
LastRow = .Cells(.Rows.Count, "A").End(xlUp).Row

For iRow = FirstRow To LastRow
If IsEmpty(.Cells(iRow, "A")) Then
'skip this row
Else
For iCtr = LBound(fCol) To UBound(fCol)
tWks.Range(tAddr(iCtr)).Value _
= .Cells(iRow, fCol(iCtr)).Value
Next iCtr
tWks.PrintOut preview:=True
End If
Next iRow
End With

End Sub


--

Dave Peterson
  #3   Report Post  
Posted to microsoft.public.excel.worksheet.functions
tjb
 
Posts: n/a
Default stopping code from looping

Awesome, now how would you go about making it go to the next line each time
the button is clicked? Until it gets to an empty row?

"Dave Peterson" wrote:

Based on the location of the activecell?

If yes, you could cheat and just change this portion:

FirstRow = 2
LastRow = .Cells(.Rows.Count, "A").End(xlUp).Row

becomes

FirstRow = activecell.row
LastRow = activecell.row
'or even
'Lastrow = firstrow

tjb wrote:

How do I modify the code below to stop running on each row with data until it
hits a blank row? I want to use a command button to execute for one row of
data only. This is a follow up to a post from Dave Petersen (he wrote the
code below) last week. Thanks all!

Private Sub Merge_Click()

Dim fWks As Worksheet
Dim tWks As Worksheet

Dim fCol As Variant
Dim tAddr As Variant

Dim iRow As Long
Dim FirstRow As Long
Dim LastRow As Long
Dim iCtr As Long

fCol = Array("a", "b", "c", "d", "e", "f", "g", "h", "i", "k", "l", "m",
"o", "p")
tAddr = Array("a1", "b1", "d12", "e13", _
"c5", "a18", "a15", "c12", "f3", "f4", _
"f17", "g9", "e1", "e2")

If UBound(fCol) < UBound(tAddr) Then
MsgBox "Design error--Not same number of columns/cells)"
End If

Set fWks = Worksheets("Entry")
Set tWks = Worksheets("Form")

With fWks
FirstRow = 2
LastRow = .Cells(.Rows.Count, "A").End(xlUp).Row

For iRow = FirstRow To LastRow
If IsEmpty(.Cells(iRow, "A")) Then
'skip this row
Else
For iCtr = LBound(fCol) To UBound(fCol)
tWks.Range(tAddr(iCtr)).Value _
= .Cells(iRow, fCol(iCtr)).Value
Next iCtr
tWks.PrintOut preview:=True
End If
Next iRow
End With

End Sub


--

Dave Peterson

  #4   Report Post  
Posted to microsoft.public.excel.worksheet.functions
Dave Peterson
 
Posts: n/a
Default stopping code from looping

At the bottom...

Activecell.offset(1,0).select



tjb wrote:

Awesome, now how would you go about making it go to the next line each time
the button is clicked? Until it gets to an empty row?

"Dave Peterson" wrote:

Based on the location of the activecell?

If yes, you could cheat and just change this portion:

FirstRow = 2
LastRow = .Cells(.Rows.Count, "A").End(xlUp).Row

becomes

FirstRow = activecell.row
LastRow = activecell.row
'or even
'Lastrow = firstrow

tjb wrote:

How do I modify the code below to stop running on each row with data until it
hits a blank row? I want to use a command button to execute for one row of
data only. This is a follow up to a post from Dave Petersen (he wrote the
code below) last week. Thanks all!

Private Sub Merge_Click()

Dim fWks As Worksheet
Dim tWks As Worksheet

Dim fCol As Variant
Dim tAddr As Variant

Dim iRow As Long
Dim FirstRow As Long
Dim LastRow As Long
Dim iCtr As Long

fCol = Array("a", "b", "c", "d", "e", "f", "g", "h", "i", "k", "l", "m",
"o", "p")
tAddr = Array("a1", "b1", "d12", "e13", _
"c5", "a18", "a15", "c12", "f3", "f4", _
"f17", "g9", "e1", "e2")

If UBound(fCol) < UBound(tAddr) Then
MsgBox "Design error--Not same number of columns/cells)"
End If

Set fWks = Worksheets("Entry")
Set tWks = Worksheets("Form")

With fWks
FirstRow = 2
LastRow = .Cells(.Rows.Count, "A").End(xlUp).Row

For iRow = FirstRow To LastRow
If IsEmpty(.Cells(iRow, "A")) Then
'skip this row
Else
For iCtr = LBound(fCol) To UBound(fCol)
tWks.Range(tAddr(iCtr)).Value _
= .Cells(iRow, fCol(iCtr)).Value
Next iCtr
tWks.PrintOut preview:=True
End If
Next iRow
End With

End Sub


--

Dave Peterson


--

Dave Peterson
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
Change case...help please Terry Excel Worksheet Functions 14 October 2nd 05 12:29 PM
Macro for changing text to Proper Case JPriest Excel Worksheet Functions 3 August 8th 05 09:31 PM
Using other workbooks.. DavidMunday Excel Worksheet Functions 2 July 1st 05 07:35 AM
Make Change Case in Excel a format rather than formula Kevin Excel Worksheet Functions 1 March 18th 05 08:53 PM
Looping macros using VB code accessuser1308 Excel Discussion (Misc queries) 2 March 9th 05 11:11 PM


All times are GMT +1. The time now is 01:52 AM.

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

About Us

"It's about Microsoft Excel"