Resize and select rows and columns

RAJESH1960

Banned for repeated rules violations
Joined
Mar 26, 2020
Messages
2,313
Office Version
  1. 2019
Platform
  1. Windows
Hello once again

The data in the columns A to H are in vertical order. I have converted the data into a horizontal order as required with the help of formulas. With the help of a code, the data was pasted in cells A3:H24 which may vary in different circumstances. What I am trying to do is select data from L3:BE7 in this case with the help of a code. The code should select cell L3, count the number of rows in column K with value and select as many rows and columns from L to BE. I have to copy that range and paste it to sheet E with paste special to remove the formulas. I also had to clear the formats from the blank cells in sheet E. for which I have added another line.
I was using this to complete it. Please note that in this sample sheet only 4 rows are to be selected. The selection may range from 100 - 500 rows in different bank sheets.
Range("L3:BE500").Select
Selection.Copy
Sheets("E").Select
Range("A3").Select
Selection.PasteSpecial Paste:=xlPasteValues, Operation:=xlNone, SkipBlanks _
:=False, Transpose:=False
With ActiveSheet.UsedRange
.Value = .Value

Book1
ABCDEFGHIJKLMNOPQRSTUVWXYZAAABACADAEAFAGAHAIAJAKALAMANAOAPAQARASATAUAVAWAXAYAZBABBBCBDBE
1
2LineDateVch TypeVch No.NarrationParticularsDebit NegativeCredit PositiveTotal AmtDateVch TypeVch No.NarrationLedger 1AmtLedger 2AmtLedger 3AmtLedger 4AmtLedger 5AmtLedger 6AmtLedger 7AmtLedger 8AmtLedger 9AmtLedger 10AmtLedger 11AmtLedger 12AmtLedger 13AmtLedger 14AmtLedger 15AmtLedger 16AmtLedger 17AmtLedger 18AmtLedger 19AmtLedger 20AmtLedger 21Amt
3130-06-2021Receipt100Bank-4040.00-4040.00130-06-2021Receipt100Bank-4040Sunday1015Monday2025Tuesday1000.5Round Off-0.5
4230-06-2021Receipt100Sunday1015.001015.00204-07-2021Payment103Bank1001January-100February-200March-300April-400Round Off-1
5330-06-2021Receipt100Monday2025.002025.00305-07-2021Receipt104Bank-4040Sunday1015Monday2025Tuesday1000.5Round Off-0.5
6430-06-2021Receipt100Tuesday1000.501000.50409-07-2021Payment107Bank1001January-100February-200March-300April-400Round Off-1
7530-06-2021Receipt100Round Off-0.50-0.50 
8804-07-2021Payment103Bank1001.001001.00 
9904-07-2021Payment103January-100.00-100.00 
101004-07-2021Payment103February-200.00-200.00 
111104-07-2021Payment103March-300.00-300.00 
121204-07-2021Payment103April-400.00-400.00 
131304-07-2021Payment103Round Off-1.00-1.00 
141405-07-2021Receipt104Bank-4040.00-4040.00 
151505-07-2021Receipt104Sunday1015.001015.00 
161605-07-2021Receipt104Monday2025.002025.00 
171705-07-2021Receipt104Tuesday1000.501000.50 
181805-07-2021Receipt104Round Off-0.50-0.50 
192109-07-2021Payment107Bank1001.001001.00 
202209-07-2021Payment107January-100.00-100.00
212309-07-2021Payment107February-200.00-200.00
222409-07-2021Payment107March-300.00-300.00
232509-07-2021Payment107April-400.00-400.00
242609-07-2021Payment107Round Off-1.00-1.00
250.00
26
B
Cell Formulas
RangeFormula
K3K3=IF(L3="","",1)
K4:K19K4=IF(L4="","",K3+1)
 

Excel Facts

Do you hate GETPIVOTDATA?
Prevent GETPIVOTDATA. Select inside a PivotTable. In the Analyze tab of the ribbon, open the dropown next to Options and turn it off
How about
VBA Code:
Sub Rajesh()
   Dim Mx As Long
   Mx = Application.Max(Range("K3:K1000"))
   Sheets("E").Range("A3:BE3").Resize(Mx).Value = Range("L3:BE3").Resize(Mx).Value
End Sub
 
Upvote 0
Solution
How about
VBA Code:
Sub Rajesh()
   Dim Mx As Long
   Mx = Application.Max(Range("K3:K1000"))
   Sheets("E").Range("A3:BE3").Resize(Mx).Value = Range("L3:BE3").Resize(Mx).Value
End Sub
Hahahahahaha. I ran the code and was waiting for the code to select the range in B sheet. After nothing happened and after sometime I checked the E sheet and the code had already given the result.
Thanks Fluff.
 
Upvote 0
How about
VBA Code:
Sub Rajesh()
   Dim Mx As Long
   Mx = Application.Max(Range("K3:K1000"))
   Sheets("E").Range("A3:BE3").Resize(Mx).Value = Range("L3:BE3").Resize(Mx).Value
End Sub
One more code to alter and my project will be completed.
 
Upvote 0
You're welcome & thanks for the feedback.
 
Upvote 0

Forum statistics

Threads
1,214,605
Messages
6,120,476
Members
448,967
Latest member
visheshkotha

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