Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 20
Default How to interpret my code

I have been given some code that should worl to get information from five
standardised docs till a new similar doc. However, as the code given is not
perfectly fitted to my doc I have trouble in getting the code work for me.
The code is (this is not all data for the process but only the data that does
not work:

private Sub GetData(LsWorkbook As String)

Dim LrDestRange As Range
Dim LrSourceRange As Range
Dim LlCounter As Long
Dim LwkbkSource As Workbook
Dim LrRange As Range
Dim LsFileFolder As String






' First Check that the format of the data is correct

With LwkbkSource.Sheets(1)
Set LrSourceRange = .Range(.Range("A1"), .Range("A1").End(xlToRight))
End With

For Each LrRange In SData.Range("Headings")

If LrRange.Offset(-1, 0).Value = "Check" Then

If Not LrSourceRange.Cells(LrRange.Column).Value = LrRange.Value Then

MsgBox "Source data is missing column " & LrRange.Column & ", value
= " & LrRange.Value

End

End If

End If

Next

' Passed the checks so paste in the data

Set LrDestRange = SData.Range("A1").End(xlDown).Offset(1, 0)

With LwkbkSource.Sheets(1)
Set LrSourceRange = .Range(.Range("A2"),
..Range("A2").End(xlDown).Offset(0, SData.Range("Headings").Columns.Count))
End With

LrDestRange.Resize(LrSourceRange.Rows.Count,
LrSourceRange.Columns.Count).Value = LrSourceRange.Value

LrDestRange.Offset(0, LrSourceRange.Columns.Count -
1).Resize(LrSourceRange.Rows.Count, 1).Value = LsWorkbook

LwkbkSource.Close

Exit Sub


So what I want to be able to do is to get my five tabs with information,
A,B,C,D,E to get copied and pasted in the new document below eachother. The
new document is called X. The thing is that the array I want to copy is from
c6:O6 and all the way down until the last row which can fluctuate. So as I
see it the code must be changed for that as well...

What other things must I do to get it to work??? for example

With LwkbkSource.Sheets(1)

what does that mean, must I change Sheets(1) for something???

I would like to keep as close to the original codeas possible, but could
anyone see and tell me what changes I need to do????
  #2   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 6,953
Default How to interpret my code

half your variables are undefined in the macro. So they should be raising
errors. Such as

With LwkbkSource

is isn't assigned a reference in this code, so know way to know what it
refers to or even if it works for you.

You need to go back to the "giver" of the code and ask questions of that
person.

--
Regards,
Tom Ogilvy




"Andreas" wrote:

I have been given some code that should worl to get information from five
standardised docs till a new similar doc. However, as the code given is not
perfectly fitted to my doc I have trouble in getting the code work for me.
The code is (this is not all data for the process but only the data that does
not work:

private Sub GetData(LsWorkbook As String)

Dim LrDestRange As Range
Dim LrSourceRange As Range
Dim LlCounter As Long
Dim LwkbkSource As Workbook
Dim LrRange As Range
Dim LsFileFolder As String






' First Check that the format of the data is correct

With LwkbkSource.Sheets(1)
Set LrSourceRange = .Range(.Range("A1"), .Range("A1").End(xlToRight))
End With

For Each LrRange In SData.Range("Headings")

If LrRange.Offset(-1, 0).Value = "Check" Then

If Not LrSourceRange.Cells(LrRange.Column).Value = LrRange.Value Then

MsgBox "Source data is missing column " & LrRange.Column & ", value
= " & LrRange.Value

End

End If

End If

Next

' Passed the checks so paste in the data

Set LrDestRange = SData.Range("A1").End(xlDown).Offset(1, 0)

With LwkbkSource.Sheets(1)
Set LrSourceRange = .Range(.Range("A2"),
.Range("A2").End(xlDown).Offset(0, SData.Range("Headings").Columns.Count))
End With

LrDestRange.Resize(LrSourceRange.Rows.Count,
LrSourceRange.Columns.Count).Value = LrSourceRange.Value

LrDestRange.Offset(0, LrSourceRange.Columns.Count -
1).Resize(LrSourceRange.Rows.Count, 1).Value = LsWorkbook

LwkbkSource.Close

Exit Sub


So what I want to be able to do is to get my five tabs with information,
A,B,C,D,E to get copied and pasted in the new document below eachother. The
new document is called X. The thing is that the array I want to copy is from
c6:O6 and all the way down until the last row which can fluctuate. So as I
see it the code must be changed for that as well...

What other things must I do to get it to work??? for example

With LwkbkSource.Sheets(1)

what does that mean, must I change Sheets(1) for something???

I would like to keep as close to the original codeas possible, but could
anyone see and tell me what changes I need to do????

  #3   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 20
Default How to interpret my code

hmmm. I cannot reach him as he's on holiday... any chance you have an idea of
how to write (and of course have time to) code that could help me, I'll
attach the whole code for the button below, but basically what I want to do
is, when pushing the button in one sheet, to copy data from 5 sheets (all
sheets are standardised) from c6:o6 to the last row which might change
depending on how many rows the input data have. Take all the rows from the
five sheets and paste into an exactly the same sheet as the others, one
problem is obvious that the numbers of rows can be different so the macro
must be flexible in where to paste in the code.

I understand if you dont have time but I would highly higlhy appreciate
it.......

"Tom Ogilvy" wrote:

half your variables are undefined in the macro. So they should be raising
errors. Such as

With LwkbkSource

is isn't assigned a reference in this code, so know way to know what it
refers to or even if it works for you.

You need to go back to the "giver" of the code and ask questions of that
person.

--
Regards,
Tom Ogilvy




"Andreas" wrote:

I have been given some code that should worl to get information from five
standardised docs till a new similar doc. However, as the code given is not
perfectly fitted to my doc I have trouble in getting the code work for me.
The code is (this is not all data for the process but only the data that does
not work:

private Sub GetData(LsWorkbook As String)

Dim LrDestRange As Range
Dim LrSourceRange As Range
Dim LlCounter As Long
Dim LwkbkSource As Workbook
Dim LrRange As Range
Dim LsFileFolder As String






' First Check that the format of the data is correct

With LwkbkSource.Sheets(1)
Set LrSourceRange = .Range(.Range("A1"), .Range("A1").End(xlToRight))
End With

For Each LrRange In SData.Range("Headings")

If LrRange.Offset(-1, 0).Value = "Check" Then

If Not LrSourceRange.Cells(LrRange.Column).Value = LrRange.Value Then

MsgBox "Source data is missing column " & LrRange.Column & ", value
= " & LrRange.Value

End

End If

End If

Next

' Passed the checks so paste in the data

Set LrDestRange = SData.Range("A1").End(xlDown).Offset(1, 0)

With LwkbkSource.Sheets(1)
Set LrSourceRange = .Range(.Range("A2"),
.Range("A2").End(xlDown).Offset(0, SData.Range("Headings").Columns.Count))
End With

LrDestRange.Resize(LrSourceRange.Rows.Count,
LrSourceRange.Columns.Count).Value = LrSourceRange.Value

LrDestRange.Offset(0, LrSourceRange.Columns.Count -
1).Resize(LrSourceRange.Rows.Count, 1).Value = LsWorkbook

LwkbkSource.Close

Exit Sub


So what I want to be able to do is to get my five tabs with information,
A,B,C,D,E to get copied and pasted in the new document below eachother. The
new document is called X. The thing is that the array I want to copy is from
c6:O6 and all the way down until the last row which can fluctuate. So as I
see it the code must be changed for that as well...

What other things must I do to get it to work??? for example

With LwkbkSource.Sheets(1)

what does that mean, must I change Sheets(1) for something???

I would like to keep as close to the original codeas possible, but could
anyone see and tell me what changes I need to do????

  #4   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 3,986
Default How to interpret my code

I second what Tom said. However,
I have tried to break the code down for you. The
portion of the code that you posted does not provide
for more than one iteration to copy from one range
to another. Since all variables are not defined,
i.e. SData, it would seem that this occurs within
one workbook, on one worksheet. However, the SData
variable could shoot that theory down. Yet it is
structured as a Private Sub which means that it is
either written for a Workbook, or a worksheet
module. Anyhow, the original code is bracketed
and the explanation then follows.


private Sub GetData(LsWorkbook As String)

Dim LrDestRange As Range
Dim LrSourceRange As Range
Dim LlCounter As Long
Dim LwkbkSource As Workbook
Dim LrRange As Range
Dim LsFileFolder As String

' First Check that the format of the data is correct

[ With LwkbkSource.Sheets(1)
Set LrSourceRange = .Range(.Range("A1"), .Range("A1").End(xlToRight))
End With]

Sets row 1 from cell A1 to the last contiguous cell
to the right that contains data as object variable.


[For Each LrRange In SData.Range("Headings")
If LrRange.Offset(-1, 0).Value = "Check" Then
If Not LrSourceRange.Cells(LrRange.Column).Value = LrRange.Value Then

MsgBox "Source data is missing column " & LrRange.Column & ", value
= " & LrRange.Value

End '(must be a typo)

End If
End If
Next]

Loops through a each cell of a range named "Headings"
and if the cell below that being evaluated equal the
word "Check" then it further evaluates a range
(and this appears to be an error) value to the search
range value and if they do not match a message box is
displayed to identify the missing data.


' Passed the checks so paste in the data

[Set LrDestRange = SData.Range("A1").End(xlDown).Offset(1, 0)]

Sets an object variable for the first empty cell in
column A that is greater than cell A1. This can be
problematic if you have data in cells beneath the first
empty cell and you paste to this cell. You will over
write any data within the scope of the range you are
pasting.

[With LwkbkSource.Sheets(1)
Set LrSourceRange = .Range(.Range("A2"),
..Range("A2").End(xlDown).Offset(0, SData.Range("Headings").Columns.Count))
End With]

Resets the object variable for LrSourceRange to cover a
range from cell A2, down to the first empty cell and
across for as many columns as are in the range
named "Headings".

[LrDestRange.Resize(LrSourceRange.Rows.Count,
LrSourceRange.Columns.Count).Value = LrSourceRange.Value]

Copies data from the LrSourceRange to the LrDestRange

[LrDestRange.Offset(0, LrSourceRange.Columns.Count -
1).Resize(LrSourceRange.Rows.Count, 1).Value = LsWorkbook]

This appears to be identifying where the data came from.
Can't be sure since LsWorkbook is not that clearly defined.



LwkbkSource.Close

Exit Sub
"Andreas" wrote:

I have been given some code that should worl to get information from five
standardised docs till a new similar doc. However, as the code given is not
perfectly fitted to my doc I have trouble in getting the code work for me.
The code is (this is not all data for the process but only the data that does
not work:

private Sub GetData(LsWorkbook As String)

Dim LrDestRange As Range
Dim LrSourceRange As Range
Dim LlCounter As Long
Dim LwkbkSource As Workbook
Dim LrRange As Range
Dim LsFileFolder As String






' First Check that the format of the data is correct

With LwkbkSource.Sheets(1)
Set LrSourceRange = .Range(.Range("A1"), .Range("A1").End(xlToRight))
End With

For Each LrRange In SData.Range("Headings")

If LrRange.Offset(-1, 0).Value = "Check" Then

If Not LrSourceRange.Cells(LrRange.Column).Value = LrRange.Value Then

MsgBox "Source data is missing column " & LrRange.Column & ", value
= " & LrRange.Value

End

End If

End If

Next

' Passed the checks so paste in the data

Set LrDestRange = SData.Range("A1").End(xlDown).Offset(1, 0)

With LwkbkSource.Sheets(1)
Set LrSourceRange = .Range(.Range("A2"),
.Range("A2").End(xlDown).Offset(0, SData.Range("Headings").Columns.Count))
End With

LrDestRange.Resize(LrSourceRange.Rows.Count,
LrSourceRange.Columns.Count).Value = LrSourceRange.Value

LrDestRange.Offset(0, LrSourceRange.Columns.Count -
1).Resize(LrSourceRange.Rows.Count, 1).Value = LsWorkbook

LwkbkSource.Close

Exit Sub


So what I want to be able to do is to get my five tabs with information,
A,B,C,D,E to get copied and pasted in the new document below eachother. The
new document is called X. The thing is that the array I want to copy is from
c6:O6 and all the way down until the last row which can fluctuate. So as I
see it the code must be changed for that as well...

What other things must I do to get it to work??? for example

With LwkbkSource.Sheets(1)

what does that mean, must I change Sheets(1) for something???

I would like to keep as close to the original codeas possible, but could
anyone see and tell me what changes I need to do????

  #5   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 6,953
Default How to interpret my code

Assuming 6 sheets in the same workbook. Copy data from 5 sheets to the 6th
Assume the data in column C, starting in C6 is contiguous and non-blank down
to the last row you want to copy.

sub abc()
Dim sh as Worksheet, v as Variant
Dim sh1 as Worksheet, rng as Range
Dim rw as Long
v = Array("Sheet1","Sheet2","Sheet3","Sheet4","Sheet5" )
set sh = worksheets("Summary")
rw = 1
for i = lbound(v) to Ubound(v)
set sh1 = worksheets(v(i))
set rng = sh1.Range(sh1.Range("C6"),sh1.Range("C6").End(xldo wn))
rng.Resize(, 13).Copy sh.Cells(rw, 1)
rw = rng.rows.count + rw
Next
End Sub

If they are not in the same workbook
sub abc()
Dim sh as Worksheet, v as Variant
Dim sh1 as Worksheet, rng as Range
Dim bk as workbook, bk1 as Workbook

Dim rw as Long
set bk = Workbooks("Mysummary.xls")
set bk1 = Workbooks("MySourceData.xls")
v = Array("Sheet1","Sheet2","Sheet3","Sheet4","Sheet5" )
set sh = bk.worksheets("Summary")
rw = 1
for i = lbound(v) to Ubound(v)
set sh1 = bk1.worksheets(v(i))
set rng = sh1.Range(sh1.Range("C6"),sh1.Range("C6").End(xldo wn))
rng.Resize(, 13).Copy sh.Cells(rw, 1)
rw = rng.rows.count + rw
Next
End Sub


--
regards,
Tom Ogilvy


"Andreas" wrote:

hmmm. I cannot reach him as he's on holiday... any chance you have an idea of
how to write (and of course have time to) code that could help me, I'll
attach the whole code for the button below, but basically what I want to do
is, when pushing the button in one sheet, to copy data from 5 sheets (all
sheets are standardised) from c6:o6 to the last row which might change
depending on how many rows the input data have. Take all the rows from the
five sheets and paste into an exactly the same sheet as the others, one
problem is obvious that the numbers of rows can be different so the macro
must be flexible in where to paste in the code.

I understand if you dont have time but I would highly higlhy appreciate
it.......

"Tom Ogilvy" wrote:

half your variables are undefined in the macro. So they should be raising
errors. Such as

With LwkbkSource

is isn't assigned a reference in this code, so know way to know what it
refers to or even if it works for you.

You need to go back to the "giver" of the code and ask questions of that
person.

--
Regards,
Tom Ogilvy




"Andreas" wrote:

I have been given some code that should worl to get information from five
standardised docs till a new similar doc. However, as the code given is not
perfectly fitted to my doc I have trouble in getting the code work for me.
The code is (this is not all data for the process but only the data that does
not work:

private Sub GetData(LsWorkbook As String)

Dim LrDestRange As Range
Dim LrSourceRange As Range
Dim LlCounter As Long
Dim LwkbkSource As Workbook
Dim LrRange As Range
Dim LsFileFolder As String






' First Check that the format of the data is correct

With LwkbkSource.Sheets(1)
Set LrSourceRange = .Range(.Range("A1"), .Range("A1").End(xlToRight))
End With

For Each LrRange In SData.Range("Headings")

If LrRange.Offset(-1, 0).Value = "Check" Then

If Not LrSourceRange.Cells(LrRange.Column).Value = LrRange.Value Then

MsgBox "Source data is missing column " & LrRange.Column & ", value
= " & LrRange.Value

End

End If

End If

Next

' Passed the checks so paste in the data

Set LrDestRange = SData.Range("A1").End(xlDown).Offset(1, 0)

With LwkbkSource.Sheets(1)
Set LrSourceRange = .Range(.Range("A2"),
.Range("A2").End(xlDown).Offset(0, SData.Range("Headings").Columns.Count))
End With

LrDestRange.Resize(LrSourceRange.Rows.Count,
LrSourceRange.Columns.Count).Value = LrSourceRange.Value

LrDestRange.Offset(0, LrSourceRange.Columns.Count -
1).Resize(LrSourceRange.Rows.Count, 1).Value = LsWorkbook

LwkbkSource.Close

Exit Sub


So what I want to be able to do is to get my five tabs with information,
A,B,C,D,E to get copied and pasted in the new document below eachother. The
new document is called X. The thing is that the array I want to copy is from
c6:O6 and all the way down until the last row which can fluctuate. So as I
see it the code must be changed for that as well...

What other things must I do to get it to work??? for example

With LwkbkSource.Sheets(1)

what does that mean, must I change Sheets(1) for something???

I would like to keep as close to the original codeas possible, but could
anyone see and tell me what changes I need to do????



  #6   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 20
Default How to interpret my code

thank a lot Tom! I really, really appreciate it. Just one thing about the
code. I am sure there always will be data in the c column however som of the
other columns in C6:o6 might be blank so I would need it to be fixed to use
columns c6:o6, is that the case right now?

Furthermore, when I'm trying to run the macro it says that the i included
isnt defined. And the last question, I understand that the "Summary" should
be replaced with my 6th tab's name, but what is Worksheets(v(i))?

Once again, thank you

Andreas

"Tom Ogilvy" wrote:

Assuming 6 sheets in the same workbook. Copy data from 5 sheets to the 6th
Assume the data in column C, starting in C6 is contiguous and non-blank down
to the last row you want to copy.

sub abc()
Dim sh as Worksheet, v as Variant
Dim sh1 as Worksheet, rng as Range
Dim rw as Long
v = Array("Sheet1","Sheet2","Sheet3","Sheet4","Sheet5" )
set sh = worksheets("Summary")
rw = 1
for i = lbound(v) to Ubound(v)
set sh1 = worksheets(v(i))
set rng = sh1.Range(sh1.Range("C6"),sh1.Range("C6").End(xldo wn))
rng.Resize(, 13).Copy sh.Cells(rw, 1)
rw = rng.rows.count + rw
Next
End Sub

If they are not in the same workbook
sub abc()
Dim sh as Worksheet, v as Variant
Dim sh1 as Worksheet, rng as Range
Dim bk as workbook, bk1 as Workbook

Dim rw as Long
set bk = Workbooks("Mysummary.xls")
set bk1 = Workbooks("MySourceData.xls")
v = Array("Sheet1","Sheet2","Sheet3","Sheet4","Sheet5" )
set sh = bk.worksheets("Summary")
rw = 1
for i = lbound(v) to Ubound(v)
set sh1 = bk1.worksheets(v(i))
set rng = sh1.Range(sh1.Range("C6"),sh1.Range("C6").End(xldo wn))
rng.Resize(, 13).Copy sh.Cells(rw, 1)
rw = rng.rows.count + rw
Next
End Sub


--
regards,
Tom Ogilvy


"Andreas" wrote:

hmmm. I cannot reach him as he's on holiday... any chance you have an idea of
how to write (and of course have time to) code that could help me, I'll
attach the whole code for the button below, but basically what I want to do
is, when pushing the button in one sheet, to copy data from 5 sheets (all
sheets are standardised) from c6:o6 to the last row which might change
depending on how many rows the input data have. Take all the rows from the
five sheets and paste into an exactly the same sheet as the others, one
problem is obvious that the numbers of rows can be different so the macro
must be flexible in where to paste in the code.

I understand if you dont have time but I would highly higlhy appreciate
it.......

"Tom Ogilvy" wrote:

half your variables are undefined in the macro. So they should be raising
errors. Such as

With LwkbkSource

is isn't assigned a reference in this code, so know way to know what it
refers to or even if it works for you.

You need to go back to the "giver" of the code and ask questions of that
person.

--
Regards,
Tom Ogilvy




"Andreas" wrote:

I have been given some code that should worl to get information from five
standardised docs till a new similar doc. However, as the code given is not
perfectly fitted to my doc I have trouble in getting the code work for me.
The code is (this is not all data for the process but only the data that does
not work:

private Sub GetData(LsWorkbook As String)

Dim LrDestRange As Range
Dim LrSourceRange As Range
Dim LlCounter As Long
Dim LwkbkSource As Workbook
Dim LrRange As Range
Dim LsFileFolder As String






' First Check that the format of the data is correct

With LwkbkSource.Sheets(1)
Set LrSourceRange = .Range(.Range("A1"), .Range("A1").End(xlToRight))
End With

For Each LrRange In SData.Range("Headings")

If LrRange.Offset(-1, 0).Value = "Check" Then

If Not LrSourceRange.Cells(LrRange.Column).Value = LrRange.Value Then

MsgBox "Source data is missing column " & LrRange.Column & ", value
= " & LrRange.Value

End

End If

End If

Next

' Passed the checks so paste in the data

Set LrDestRange = SData.Range("A1").End(xlDown).Offset(1, 0)

With LwkbkSource.Sheets(1)
Set LrSourceRange = .Range(.Range("A2"),
.Range("A2").End(xlDown).Offset(0, SData.Range("Headings").Columns.Count))
End With

LrDestRange.Resize(LrSourceRange.Rows.Count,
LrSourceRange.Columns.Count).Value = LrSourceRange.Value

LrDestRange.Offset(0, LrSourceRange.Columns.Count -
1).Resize(LrSourceRange.Rows.Count, 1).Value = LsWorkbook

LwkbkSource.Close

Exit Sub


So what I want to be able to do is to get my five tabs with information,
A,B,C,D,E to get copied and pasted in the new document below eachother. The
new document is called X. The thing is that the array I want to copy is from
c6:O6 and all the way down until the last row which can fluctuate. So as I
see it the code must be changed for that as well...

What other things must I do to get it to work??? for example

With LwkbkSource.Sheets(1)

what does that mean, must I change Sheets(1) for something???

I would like to keep as close to the original codeas possible, but could
anyone see and tell me what changes I need to do????

  #7   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 20
Default How to interpret my code

one more thing that I forgot to mention (sorry for my stupidness). I do have
a calculate button to where I will attach the code but what I also have is a
listbox, with the five sheets (the one's I want to copy from). I just want to
have the marked sheets copied, i.e. if the user has marked 1 &, just these
two should be copied...

"Andreas" wrote:

thank a lot Tom! I really, really appreciate it. Just one thing about the
code. I am sure there always will be data in the c column however som of the
other columns in C6:o6 might be blank so I would need it to be fixed to use
columns c6:o6, is that the case right now?

Furthermore, when I'm trying to run the macro it says that the i included
isnt defined. And the last question, I understand that the "Summary" should
be replaced with my 6th tab's name, but what is Worksheets(v(i))?

Once again, thank you

Andreas

"Tom Ogilvy" wrote:

Assuming 6 sheets in the same workbook. Copy data from 5 sheets to the 6th
Assume the data in column C, starting in C6 is contiguous and non-blank down
to the last row you want to copy.

sub abc()
Dim sh as Worksheet, v as Variant
Dim sh1 as Worksheet, rng as Range
Dim rw as Long
v = Array("Sheet1","Sheet2","Sheet3","Sheet4","Sheet5" )
set sh = worksheets("Summary")
rw = 1
for i = lbound(v) to Ubound(v)
set sh1 = worksheets(v(i))
set rng = sh1.Range(sh1.Range("C6"),sh1.Range("C6").End(xldo wn))
rng.Resize(, 13).Copy sh.Cells(rw, 1)
rw = rng.rows.count + rw
Next
End Sub

If they are not in the same workbook
sub abc()
Dim sh as Worksheet, v as Variant
Dim sh1 as Worksheet, rng as Range
Dim bk as workbook, bk1 as Workbook

Dim rw as Long
set bk = Workbooks("Mysummary.xls")
set bk1 = Workbooks("MySourceData.xls")
v = Array("Sheet1","Sheet2","Sheet3","Sheet4","Sheet5" )
set sh = bk.worksheets("Summary")
rw = 1
for i = lbound(v) to Ubound(v)
set sh1 = bk1.worksheets(v(i))
set rng = sh1.Range(sh1.Range("C6"),sh1.Range("C6").End(xldo wn))
rng.Resize(, 13).Copy sh.Cells(rw, 1)
rw = rng.rows.count + rw
Next
End Sub


--
regards,
Tom Ogilvy


"Andreas" wrote:

hmmm. I cannot reach him as he's on holiday... any chance you have an idea of
how to write (and of course have time to) code that could help me, I'll
attach the whole code for the button below, but basically what I want to do
is, when pushing the button in one sheet, to copy data from 5 sheets (all
sheets are standardised) from c6:o6 to the last row which might change
depending on how many rows the input data have. Take all the rows from the
five sheets and paste into an exactly the same sheet as the others, one
problem is obvious that the numbers of rows can be different so the macro
must be flexible in where to paste in the code.

I understand if you dont have time but I would highly higlhy appreciate
it.......

"Tom Ogilvy" wrote:

half your variables are undefined in the macro. So they should be raising
errors. Such as

With LwkbkSource

is isn't assigned a reference in this code, so know way to know what it
refers to or even if it works for you.

You need to go back to the "giver" of the code and ask questions of that
person.

--
Regards,
Tom Ogilvy




"Andreas" wrote:

I have been given some code that should worl to get information from five
standardised docs till a new similar doc. However, as the code given is not
perfectly fitted to my doc I have trouble in getting the code work for me.
The code is (this is not all data for the process but only the data that does
not work:

private Sub GetData(LsWorkbook As String)

Dim LrDestRange As Range
Dim LrSourceRange As Range
Dim LlCounter As Long
Dim LwkbkSource As Workbook
Dim LrRange As Range
Dim LsFileFolder As String






' First Check that the format of the data is correct

With LwkbkSource.Sheets(1)
Set LrSourceRange = .Range(.Range("A1"), .Range("A1").End(xlToRight))
End With

For Each LrRange In SData.Range("Headings")

If LrRange.Offset(-1, 0).Value = "Check" Then

If Not LrSourceRange.Cells(LrRange.Column).Value = LrRange.Value Then

MsgBox "Source data is missing column " & LrRange.Column & ", value
= " & LrRange.Value

End

End If

End If

Next

' Passed the checks so paste in the data

Set LrDestRange = SData.Range("A1").End(xlDown).Offset(1, 0)

With LwkbkSource.Sheets(1)
Set LrSourceRange = .Range(.Range("A2"),
.Range("A2").End(xlDown).Offset(0, SData.Range("Headings").Columns.Count))
End With

LrDestRange.Resize(LrSourceRange.Rows.Count,
LrSourceRange.Columns.Count).Value = LrSourceRange.Value

LrDestRange.Offset(0, LrSourceRange.Columns.Count -
1).Resize(LrSourceRange.Rows.Count, 1).Value = LsWorkbook

LwkbkSource.Close

Exit Sub


So what I want to be able to do is to get my five tabs with information,
A,B,C,D,E to get copied and pasted in the new document below eachother. The
new document is called X. The thing is that the array I want to copy is from
c6:O6 and all the way down until the last row which can fluctuate. So as I
see it the code must be changed for that as well...

What other things must I do to get it to work??? for example

With LwkbkSource.Sheets(1)

what does that mean, must I change Sheets(1) for something???

I would like to keep as close to the original codeas possible, but could
anyone see and tell me what changes I need to do????

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
Determine and interpret the P-Value roystonteo via OfficeKB.com Excel Discussion (Misc queries) 2 February 6th 09 05:34 AM
How does VBA interpret Dates? Greg Glynn Excel Programming 2 July 10th 07 03:28 AM
Interpret code FIRSTROUNDKO via OfficeKB.com Excel Programming 4 March 22nd 06 06:21 PM
Why does Excel interpret 2/29 as Feb 1st? Jo Excel Discussion (Misc queries) 6 February 26th 05 06:06 PM
Could some one please help me to interpret the following syntax Augustus Excel Programming 5 March 3rd 04 09:55 AM


All times are GMT +1. The time now is 04:24 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"