Copy individual range based on highlighted last cell from sheet to another

KalilMe

Active Member
Joined
Mar 5, 2021
Messages
343
Office Version
  1. 2016
Platform
  1. Windows
Hello
I want copying for each range just contains higlighted cell in column H for the last row (SUMMING) from sheet to another
source data
Copy of TR.xlsm
ABCDEFGH
1CODE
2FR-00
3ITEMDATEGOODSTYPEPRQTYUNITTOTAL
4101/01/2021BANANAFOPL200.0012.002400.00
5207/01/2021BANANAFOPL450.0012.005400.00
6308/01/2021BANANAFOPL500.0019.579785.71
7414/01/2021BANANAFOPL800.0025.3620285.71
8515/01/2021BANANAFOPL850.0026.3222373.21
9SUMMING2800.0060244.64
10
11
12CODE
13FR-01
14ITEMDATEGOODSTYPEPRQTYUNITTOTAL
15102/01/2021APPLEFRPPL100.0014.001400.00
16209/01/2021APPLEFRPPL550.0020.5411294.64
17316/01/2021APPLEFRPPL900.0027.2924557.14
18SUMMING1550.0037251.79
19
20
21CODE
22FR-02
23ITEMDATEGOODSTYPEPRQTYUNITTOTAL
24103/01/2021PEACHFRLLP300.0015.004500.00
25210/01/2021PEACHFRLLP600.0021.5012900.00
26317/01/2021PEACHFRLLP950.0028.2526837.50
27SUMMING1850.0044237.50
28
29
30CODE
31FR-03
32ITEMDATEGOODSTYPEPRQTYUNITTOTAL
33104/01/2021PEARFRTTL300.0012.003600.00
34211/01/2021PEARFRTTL650.0022.4614601.79
35318/01/2021BANANAFOPL1000.0029.2129214.29
36SUMMING1950.0047416.07
37
38
39CODE
40FR-04
41ITEMDATEGOODSTYPEPRQTYUNITTOTAL
42105/01/2021STRWBERRAYFRMML350.0020.007000.00
43212/01/2021STRWBERRAYFRMML700.0023.4316400.00
44319/01/2021APPLEFRPPL1050.0030.1831687.50
45SUMMING2100.0055087.50
RETSEL


result like this
Copy of TR.xlsm
ABCDEFGH
1CODE
2FR-00
3ITEMDATEGOODSTYPEPRQTYUNITTOTAL
4101/01/2021BANANAFOPL200.0012.002400.00
5207/01/2021BANANAFOPL450.0012.005400.00
6308/01/2021BANANAFOPL500.0019.579785.71
7414/01/2021BANANAFOPL800.0025.3620285.71
8515/01/2021BANANAFOPL850.0026.3222373.21
9SUMMING2800.0060244.64
10
11
12CODE
13FR-02
14ITEMDATEGOODSTYPEPRQTYUNITTOTAL
15103/01/2021PEACHFRLLP300.0015.004500.00
16210/01/2021PEACHFRLLP600.0021.5012900.00
17317/01/2021PEACHFRLLP950.0028.2526837.50
18SUMMING1850.0044237.50
19
20
21CODE
22FR-04
23ITEMDATEGOODSTYPEPRQTYUNITTOTAL
24105/01/2021STRWBERRAYFRMML350.0020.007000.00
25212/01/2021STRWBERRAYFRMML700.0023.4316400.00
26319/01/2021APPLEFRPPL1050.0030.1831687.50
27SUMMING2100.0055087.50
result


note: the data are increasable and changeable in sheet RETSEL
 
Waiting for your results when running StartAllMacrosFormHere
I don't know what it is, but seems to be something funny happening with that StartAllMacrosFormHere procedure.
I went through all the individual procedures and added a line to write the timer results (number only) to the Remarks sheet col M immediately after the Debug.Print line and then ran the StartAllMacrosFormHere procedure.
I manually moved those results from col M to col L and then went back and ran each of the procedures individually, still with the results going to 'Remarks' col M
Below are my results. You wouldn't expect the results to be identical but it looks like there could be something unusual with the second procedure and something definitely unusual with the final one.

Copy Ranges Test WB AnySheet230112.xlsm
LMN
1StartAllMacrosFormHereIndividual Procedures
22.232.38106.73%
31.871.0656.68%
42.462.3394.72%
52.442.3696.72%
60.480.59122.92%
72.192.23101.83%
80.230.26113.04%
98.517.588.13%
102.110.199.00%
Remarks
Cell Formulas
RangeFormula
N2:N10N2=M2/L2
 
Upvote 0

Excel Facts

Round to nearest half hour?
Use =MROUND(A2,"0:30") to round to nearest half hour. Use =CEILING(A2,"0:30") to round to next half hour.
Hi PeterSSs,

all I can do is confirm what you point out.

Running your code alone brings up
Rich (BB code):
0,44140625 sec for procedure 'Copy_Blocks_45' by Peter_SSs
0,375 sec for procedure 'Copy_Blocks_45' by Peter_SSs
0,44140625 sec for procedure 'Copy_Blocks_45' by Peter_SSs
while last position in caller (all kvsrinivasamurthy codes except DataColoured_43 deactivated)
Rich (BB code):
1,5390625 sec for procedure 'Copy_Blocks_45' by Peter_SSs
Running only these two codes from caller:
Rich (BB code):
0,51953125 sec for procedure 'MrE_1226327_26' by HaHoBe
0,36328125 sec for procedure 'Copy_Blocks_45' by Peter_SSs

First of all I can only state that your code is the fastest provided no matter what the lines in the Immediate Window or on the sheet say. And times (if less than one second) should be monitored by something else than Timer (but I wonder if that would be worth altering the code if available when you have the feeling the code is doing the job properly and fast enough for you).

Holger
 
Upvote 0
but I wonder if that would be worth altering the code if available when you have the feeling the code is doing the job properly and fast enough for you
I agree. Use the code that you are most comfortable with if you are happy with the accuracy and speed. :)

Thanks for double-checking the different timings though. (y)
 
Upvote 0
There is only one thing left open for me.

In #23 kvsrinivasamurthy posted code which was marked to raise a run-time error 1004 by KalilMe in #24 and by me in #36 (with number of rows checked and a dump of the immediate window). Using the absolute addresses will not really be of help as that means 4 extra characters per Address for the $

In fact it seems that range can only take a string with a length of 256 characters (using Select here is just for demonstration), strAdr1 for the second loop will raise the error:

VBA Code:
Sub TestRangeLimitString()
Dim strAdr1 As String
Dim lngCnt As Long
Dim lngLoop As Long
Dim lngStep As Long
Dim strAdr2 As String

For lngLoop = 1 To 2
  strAdr1 = vbNullString
  strAdr2 = vbNullString
  lngStep = 10 - lngLoop
  For lngCnt = 1 To 180 Step lngStep
    strAdr1 = strAdr1 & Range(Cells(lngCnt, 1), Cells(lngCnt + 5, 8)).Address & ","
    strAdr2 = strAdr2 & Range(Cells(lngCnt, 1), Cells(lngCnt + 5, 8)).Address(0, 0) & ","
  Next lngCnt
  Debug.Print "length of string2: " & Len(strAdr2) & vbCrLf & Left(strAdr2, Len(strAdr2) - 1)
  Range(Left(strAdr2, Len(strAdr2) - 1)).Select
  Debug.Print "length of string1: " & Len(strAdr1) & vbCrLf & Left(strAdr1, Len(strAdr1) - 1)
  Range(Left(strAdr1, Len(strAdr1) - 1)).Select
Next lngLoop
End Sub

On the DataSet I used in the sample sheet (FR-001 to FR750) the codes with a similar codeline like If Adr <> "" Then Range(Mid(Adr, 2)).Delete Shift:=xlUp work if the relative address is used for FR-001 to FR-039 (A1:H511).

Holger
 
Upvote 0

Forum statistics

Threads
1,216,070
Messages
6,128,614
Members
449,460
Latest member
jgharbawi

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top