Antoher piece of code to modify please Help!!![Resolved]
Hello I have a code here that will find any bold cells in one sheet and caopy that cell and its row to another sheet (thanks Opus and RobDog888), Well my Co-worker had his friend come up with this code that works as well
VB Code:
Sub TransferDataPlease()
Dim i As Long, n As Long
Dim Sh1 As Worksheet, Sh2 As Worksheet
Set Sh1 = ActiveSheet
Set Sh2 = Worksheets("Results") ' insert name here
n = 1
For x = Sh1.Range("A65536").End(xlUp).Row To 3 Step -1
y = 0
IsBold = False
Do
y = y + 1
If Sh1.Cells(x, y).Font.Bold = True Then IsBold = True
Loop While y <= 13 And IsBold = False ' Checks first 13 cols
If IsBold Then
n = n + 1
Sh1.Range("A" & x).EntireRow.Copy Sh2.Range("A" & n)
End If
Next x
End Sub
..Works Fantastic but there is a problem....It pasted the Data from the Bottom to the top on Worksheet2 (example if it were 3 rows to be pasted...instead of pasting row 1of workshheta to row 1 of worksheet b..it would paste row 1 of A into row 3 of B...kinda upsidedown....)
.... i think the problem is here.
VB Code:
For x = Sh1.Range("A65536").End(xlUp).Row To 3 Step -1
Because its searching for results from the bottom to the top.But when i try to modify it by flipping the arguments, it tells me that there is an " expected end of statment error"
Can someone help me out here?
thanks for taking a look.
Re: Antoher piece of code to modify please Help!!!
Looks like it is looping through the ENTIRE spreadsheet!!! from bottom to top.
You dont need to do that at all. You can use the SpecialCells function to find
the last used row or column in the spreadsheet instead. Also, no need to
start from the bottom and move up. We can iterate from the top down.
VB Code:
Workbooks("Book1").Sheets("Sheet1").Cells.SpecialCells(xlCellTypeLastCell).Row
Re: Antoher piece of code to modify please Help!!!
Thanks for the quick response RobDog888 so i tried this:
VB Code:
For x = Sheets("Console").Cells.SpecialCells(xlCellTypeLastCell).Row To 3
Instead of this :
VB Code:
For x = Sh1.Range("A65536").End(xlUp).Row To 3 Step -1
And it still pasted from the Bottom to top... :confused:
I thought with the code on the top...it would go from top to last used cell.
is that not right?
Re: Antoher piece of code to modify please Help!!!
It should be...
VB Code:
For x = 3 To Sheets("Console").Cells.SpecialCells(xlCellTypeLastCell).Row
Re: Antoher piece of code to modify please Help!!![Resolved]
Looks like we're good to go .....So Far
Thanks for all your help robDog888
Re: Antoher piece of code to modify please Help!!![Resolved]