ExcelBanter

ExcelBanter (https://www.excelbanter.com/)
-   Excel Programming (https://www.excelbanter.com/excel-programming/)
-   -   What have I got wrong? (Macro),,, (https://www.excelbanter.com/excel-programming/281685-what-have-i-got-wrong-macro.html)

ste mac

What have I got wrong? (Macro),,,
 
Hello to all, I have almost got this thing working, my problem is
that it will not 'select' the correct sheet before looking for the
'idNumber'.. and l just don't know why... I have been messing
around with it for a couple of days... I think the rest of the
code will work once it finds the idNumber on the rightsheet..

Thanks for any help you can give...seeya ste


sub getdepthvalue()

Dim SheetName As String
Dim sheetNumber As Long
Dim rightSheet As Long
Dim idNumber As String
Dim activeid As String
Dim xlrow As Long
Dim scennumber As Variant
Dim thedepth As Long
Dim copyrange As Range

Sheets("Live History").Select
Sheets("Live History").Range("N1").End(xlDown).Select
ActiveCell.Offset(0, 5).Select
idNumber = ActiveCell.Value

For sheetNumber = 1 To 56

xlrow = 3

SheetName = "S" & Format(sheetNumber, "##0")
Sheets(SheetName).Select

rightSheet = Sheets("Live History").Range("H1").End(xlDown).Value
scennumber = ActiveSheet.Cells(3, 2).Value

If rightSheet = scennumber Then
ActiveSheet.Range("A3").Select
End If

Do Until ActiveCell.Value = idNumber
ActiveCell.Offset(1, 0).Select
Loop
If ActiveCell.Value = idNumber Then
ActiveCell.Offset(0, 9).Select
End If
ActiveCell.Copy
Set copyrange = ActiveCell
Sheets("Live History").Select
ActiveSheet.Range("P1").End(xlDown).Offset(1, 0).PasteSpecial Paste:=xlPasteValues

End

Next
End

importdata
End Sub

Don Guillett[_4_]

What have I got wrong? (Macro),,,
 
try
idnumber=Sheets("Live History").Range("N1").End(xlDown).Offset(0, 5)


"ste mac" wrote in message
om...
Hello to all, I have almost got this thing working, my problem is
that it will not 'select' the correct sheet before looking for the
'idNumber'.. and l just don't know why... I have been messing
around with it for a couple of days... I think the rest of the
code will work once it finds the idNumber on the rightsheet..

Thanks for any help you can give...seeya ste


sub getdepthvalue()

Dim SheetName As String
Dim sheetNumber As Long
Dim rightSheet As Long
Dim idNumber As String
Dim activeid As String
Dim xlrow As Long
Dim scennumber As Variant
Dim thedepth As Long
Dim copyrange As Range

Sheets("Live History").Select
Sheets("Live History").Range("N1").End(xlDown).Select
ActiveCell.Offset(0, 5).Select
idNumber = ActiveCell.Value

For sheetNumber = 1 To 56

xlrow = 3

SheetName = "S" & Format(sheetNumber, "##0")
Sheets(SheetName).Select

rightSheet = Sheets("Live History").Range("H1").End(xlDown).Value
scennumber = ActiveSheet.Cells(3, 2).Value

If rightSheet = scennumber Then
ActiveSheet.Range("A3").Select
End If

Do Until ActiveCell.Value = idNumber
ActiveCell.Offset(1, 0).Select
Loop
If ActiveCell.Value = idNumber Then
ActiveCell.Offset(0, 9).Select
End If
ActiveCell.Copy
Set copyrange = ActiveCell
Sheets("Live History").Select
ActiveSheet.Range("P1").End(xlDown).Offset(1, 0).PasteSpecial

Paste:=xlPasteValues

End

Next
End

importdata
End Sub




ste mac

What have I got wrong? (Macro),,,
 
Thanks Don... nice one...

seeya ste


All times are GMT +1. The time now is 09:52 PM.

Powered by vBulletin® Copyright ©2000 - 2024, Jelsoft Enterprises Ltd.
ExcelBanter.com