Range Offset Help

AsgiE

New Member
Joined
May 26, 2005
Messages
44
Hi,
I need guidance on how I can reduce the range selected in row 4 by 1 row.
The selection. Offset syntax moves the entire selection one row up and overwrites one of the rows above the range.

:confused:
I just want the range to be reduced by 1 row.
Any help will be greatly appreciated
Thanks

Range("D9").Select
Selection.End(xlDown).Select
Selection.Copy
Range(Selection, Selection.End(xlDown)).Select
Selection.Offset(-1, 0).Select
ActiveSheet.Paste
Application.CutCopyMode = False
 

Excel Facts

Can you sort left to right?
To sort left-to-right, use the Sort dialog box. Click Options. Choose "Sort left to right"
No I get a "runtime error 1004" with the usual "application-defined or object defined error"
 
Upvote 0
You rarely ever need to Select anything to work with it in VBA. That being said, try inserting this after your 4th line:

Code:
Selection.Resize(Selection.Rows.Count-1).Select
 
Upvote 0
So what are we trying to do, copy the range beginning in Cell D9 to the second last row of your data then pasting it 1 row after the last row?

I can write something much simpler than what you have above, without all those selects and maybe only in 1-2 lines
 
Upvote 0
that worked as expected. Appreciate the help.
This is a quick script to copy down "names" into blank cells below with active records. The names only appear on the first row.
What would be a quicker method. I have thought about using the fill down syntax but not applied it yet.
Thanks
 
Upvote 0
Yes that is essentially what I am trying to do. Any help with simplification would be appreciated.
Thanks
 
Upvote 0
Here's an example (might have to be changed if your data structure isn't what I've guessed it to be):


Excel 2003
ABCD
9Name1
10Record1
11Record2
12Record3
13Record4
14Record5
15Record6
16Record7
17Record8
18Record9
19Record10
20Record11
21Record12
22Record13
23Record14
24Record15
25Record16
26Record17
27Record18
28Record19
29Record20
30Record21
31Record22
Sheet3



Code:
Sub testcopydown()
Range("D9").Copy Destination:=Range("D10:D" & Cells(Rows.Count, 1).End(xlUp).Row - 1)
End Sub


Excel 2003
ABCD
9Name1
10Record1Name1
11Record2Name1
12Record3Name1
13Record4Name1
14Record5Name1
15Record6Name1
16Record7Name1
17Record8Name1
18Record9Name1
19Record10Name1
20Record11Name1
21Record12Name1
22Record13Name1
23Record14Name1
24Record15Name1
25Record16Name1
26Record17Name1
27Record18Name1
28Record19Name1
29Record20Name1
30Record21Name1
31Record22
Sheet3
 
Upvote 0
[TABLE="class: grid, width: 150, align: left"]
<TBODY>[TR]
[TD]Record1[/TD]
[TD]Name1[/TD]
[/TR]
[TR]
[TD]Record2[/TD]
[TD][/TD]
[/TR]
[TR]
[TD]Record3[/TD]
[TD][/TD]
[/TR]
[TR]
[TD]Record4[/TD]
[TD][/TD]
[/TR]
[TR]
[TD]Record5[/TD]
[TD][/TD]
[/TR]
[TR]
[TD]Record6[/TD]
[TD]Name2[/TD]
[/TR]
[TR]
[TD]Record7[/TD]
[TD][/TD]
[/TR]
[TR]
[TD]Record8[/TD]
[TD][/TD]
[/TR]
[TR]
[TD]Record9[/TD]
[TD][/TD]
[/TR]
[TR]
[TD]Record10[/TD]
[TD][/TD]
[/TR]
[TR]
[TD]Record11[/TD]
[TD]Name3[/TD]
[/TR]
[TR]
[TD]Record12[/TD]
[TD][/TD]
[/TR]
[TR]
[TD]Record13[/TD]
[TD][/TD]
[/TR]
[TR]
[TD]Record14[/TD]
[TD][/TD]
[/TR]
[TR]
[TD]Record15[/TD]
[TD][/TD]
[/TR]
[TR]
[TD]Record16[/TD]
[TD]Name4[/TD]
[/TR]
[TR]
[TD]Record17[/TD]
[TD][/TD]
[/TR]
[TR]
[TD]Record18[/TD]
[TD][/TD]
[/TR]
[TR]
[TD]Record19[/TD]
[TD][/TD]
[/TR]
[TR]
[TD]Record20[/TD]
[TD][/TD]
[/TR]
</TBODY>[/TABLE]
































In the above I needed to fill in Record2 to Record5 with Name1 and Record7 to Record10 with Name2 and so on. Hope this clarifies the requirement and again many thanks for the help from this forum.
Regards
Asgi
 
Upvote 0
select the name column or range, hit f5-special-blanks, then type =d9 (or wherever the first Name1 is) and hit ctrl-enter


(if this won't work for you because it's not in VBA tell me and I'll give you some code lines)
 
Upvote 0

Forum statistics

Threads
1,223,911
Messages
6,175,337
Members
452,637
Latest member
Ezio2866

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