ExcelBanter

ExcelBanter (https://www.excelbanter.com/)
-   Excel Programming (https://www.excelbanter.com/excel-programming/)
-   -   Copy to datasheet -Message for Ron De Bruin (https://www.excelbanter.com/excel-programming/404695-copy-datasheet-message-ron-de-bruin.html)

Tredown

Copy to datasheet -Message for Ron De Bruin
 
I an using your copy next each other sub and last row function.
My question is there a maximum number of ranges that can be used within the
Set sourceRange = Sheets("Sheet1").Range statement. I have 41 ranges which
works fine but as soon as i add further ranges i get a run time error 1004.
If there is a maximum is there away to increase it.
Thanks in anticipation
Tredown

Ron de Bruin

Copy to datasheet -Message for Ron De Bruin
 
Hi Tredown

Can you give me the link to the macro example you use now
We can find a solution for you then

--

Regards Ron de Bruin
http://www.rondebruin.nl/tips.htm


"Tredown" wrote in message ...
I an using your copy next each other sub and last row function.
My question is there a maximum number of ranges that can be used within the
Set sourceRange = Sheets("Sheet1").Range statement. I have 41 ranges which
works fine but as soon as i add further ranges i get a run time error 1004.
If there is a maximum is there away to increase it.
Thanks in anticipation
Tredown


Tredown

Copy to datasheet -Message for Ron De Bruin
 
Hi Ron
Thanks for replying, this the macro and function I am using
Function LastRow(sh As Worksheet)
On Error Resume Next
LastRow = sh.Cells.Find(What:="*", _
After:=sh.Range("A1"), _
Lookat:=xlPart, _
LookIn:=xlFormulas, _
SearchOrder:=xlByRows, _
SearchDirection:=xlPrevious, _
MatchCase:=False).Row
On Error GoTo 0
End Function


Sub Copy_Next_Each_Other()
Dim smallrng As Range, DestRange As Range
Dim DestSheet As Worksheet, Lr As Long
Dim SourceRange As Range, I As Integer

With Application
.ScreenUpdating = False
.EnableEvents = False
End With

'fill in the Source Sheet and range
Set SourceRange =
Sheets("Sheet1").Range("J3,F6:G6,F7:G7,F8:G8,F9,F1 0,G11,F12:G12,F16:G16,F17:G17,F18:G18,F19:G19,F20: G20,F21:G21,F22:G22,F23:G23,F24:G24,F25:G25,F26:G2 6,F27:G27,F28:G28,F29:G29,F32,F33:G33,F34:G34,F35: G35,F36:G36,F37:G37,N6:O6,N7:O7,N8,N9,N11,N12,N13, N14,N15,O16,O17,N18:O18")

'Fill in the destination sheet and call the LastRow
'function to find last row
Set DestSheet = Sheets("Data")
Lr = LastRow(DestSheet)
I = 1

For Each smallrng In SourceRange.Areas

'We make DestRange the same size as smallrng and use the
'Value property to give DestRange the same values
With smallrng
Set DestRange = DestSheet.Cells(Lr + 1, I) _
.Resize(.Rows.Count, .Columns.Count)
End With
DestRange.Value = smallrng.Value
I = I + smallrng.Columns.Count

Next smallrng

With Application
.ScreenUpdating = True
.EnableEvents = True
End With
Range("J3,D6:E14,G6:G8,G10:G14,D16:E30,G16:G30,D32 :E37,G33:G37,L6:M9,O6:O7,L11:M15,O16:O21,L18:M30,O 33,L35:L36,L40").Select
Selection.ClearContents
End Sub

regards
Tredown


"Ron de Bruin" wrote:

Hi Tredown

Can you give me the link to the macro example you use now
We can find a solution for you then

--

Regards Ron de Bruin
http://www.rondebruin.nl/tips.htm


"Tredown" wrote in message ...
I an using your copy next each other sub and last row function.
My question is there a maximum number of ranges that can be used within the
Set sourceRange = Sheets("Sheet1").Range statement. I have 41 ranges which
works fine but as soon as i add further ranges i get a run time error 1004.
If there is a maximum is there away to increase it.
Thanks in anticipation
Tredown



Ron de Bruin

Copy to datasheet -Message for Ron De Bruin
 
Hi Tredown

One workaround of this limit you hit is to read the tip above the macro.
It is easer to maintain also then if you use so many areas of ranges

Tip: Use a row below your data with links to cells you want (=C3 in A50, =G15 in B50, €¦..).
You can hide this row if you want and copy a range like A50:Z50 for example with one of the
one area examples above

--

Regards Ron de Bruin
http://www.rondebruin.nl/tips.htm


"Tredown" wrote in message ...
Hi Ron
Thanks for replying, this the macro and function I am using
Function LastRow(sh As Worksheet)
On Error Resume Next
LastRow = sh.Cells.Find(What:="*", _
After:=sh.Range("A1"), _
Lookat:=xlPart, _
LookIn:=xlFormulas, _
SearchOrder:=xlByRows, _
SearchDirection:=xlPrevious, _
MatchCase:=False).Row
On Error GoTo 0
End Function


Sub Copy_Next_Each_Other()
Dim smallrng As Range, DestRange As Range
Dim DestSheet As Worksheet, Lr As Long
Dim SourceRange As Range, I As Integer

With Application
.ScreenUpdating = False
.EnableEvents = False
End With

'fill in the Source Sheet and range
Set SourceRange =
Sheets("Sheet1").Range("J3,F6:G6,F7:G7,F8:G8,F9,F1 0,G11,F12:G12,F16:G16,F17:G17,F18:G18,F19:G19,F20: G20,F21:G21,F22:G22,F23:G23,F24:G24,F25:G25,F26:G2 6,F27:G27,F28:G28,F29:G29,F32,F33:G33,F34:G34,F35: G35,F36:G36,F37:G37,N6:O6,N7:O7,N8,N9,N11,N12,N13, N14,N15,O16,O17,N18:O18")

'Fill in the destination sheet and call the LastRow
'function to find last row
Set DestSheet = Sheets("Data")
Lr = LastRow(DestSheet)
I = 1

For Each smallrng In SourceRange.Areas

'We make DestRange the same size as smallrng and use the
'Value property to give DestRange the same values
With smallrng
Set DestRange = DestSheet.Cells(Lr + 1, I) _
.Resize(.Rows.Count, .Columns.Count)
End With
DestRange.Value = smallrng.Value
I = I + smallrng.Columns.Count

Next smallrng

With Application
.ScreenUpdating = True
.EnableEvents = True
End With
Range("J3,D6:E14,G6:G8,G10:G14,D16:E30,G16:G30,D32 :E37,G33:G37,L6:M9,O6:O7,L11:M15,O16:O21,L18:M30,O 33,L35:L36,L40").Select
Selection.ClearContents
End Sub

regards
Tredown


"Ron de Bruin" wrote:

Hi Tredown

Can you give me the link to the macro example you use now
We can find a solution for you then

--

Regards Ron de Bruin
http://www.rondebruin.nl/tips.htm


"Tredown" wrote in message ...
I an using your copy next each other sub and last row function.
My question is there a maximum number of ranges that can be used within the
Set sourceRange = Sheets("Sheet1").Range statement. I have 41 ranges which
works fine but as soon as i add further ranges i get a run time error 1004.
If there is a maximum is there away to increase it.
Thanks in anticipation
Tredown





All times are GMT +1. The time now is 12:04 AM.

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