Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 1
Default Confused - Range and Cells


Hi,

I'm having no problems with selecting and manipulating single cell
with variables but don't understand how to convert this to working wit
Range. For example, in a macro I''ll find a row with the text "Starts:
in column A. Working on any single cell (or complete row) reference
from that start point isn't a problem, but if I want to work with mor
than one cell, I do it one cell at a time because I can't figure ou
how to select more than one using a Range with variables.

I currently use this to delete some cells (columns I to M) and the
move columns A to I to columns J to R.

cLastRow = Cells(Rows.Count, "A").End(xlUp).Row
For r = cLastRow To 1 Step -1
If InStr(1, Cells(r, "A"), "Starts:") 0 Then
Cells(r, "I").Select
Selection.Delete Shift:=xlToLeft
Selection.Delete Shift:=xlToLeft
Selection.Delete Shift:=xlToLeft
Selection.Delete Shift:=xlToLeft
Selection.Delete Shift:=xlToLeft
Selection.Cut Destination:=Cells(r, "R")
Cells(r, "H").Select
Selection.Cut Destination:=Cells(r, "Q")
Cells(r, "G").Select
Selection.Cut Destination:=Cells(r, "P")
Cells(r, "F").Select
Selection.Cut Destination:=Cells(r, "O")
Cells(r, "E").Select
Selection.Cut Destination:=Cells(r, "N")
Cells(r, "D").Select
Selection.Cut Destination:=Cells(r, "M")
Cells(r, "C").Select
Selection.Cut Destination:=Cells(r, "L")
Cells(r, "B").Select
Selection.Cut Destination:=Cells(r, "K")
Cells(r, "A").Select
Selection.Cut Destination:=Cells(r, "J")
End If
Next r

Very messy but it works.

I then use a similar procedure later to move the same range back t
column A (need to get them out of the way for some text to colum
stuff). I know it can be simplified with a range, but how do I do it

--
Mark
-----------------------------------------------------------------------
Mark K's Profile: http://www.excelforum.com/member.php...fo&userid=1411
View this thread: http://www.excelforum.com/showthread.php?threadid=57382

  #2   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 1
Default Confused - Range and Cells


Never mind, figured it out (with a little help from the recorder) using
offsets from the active cell. So now I have this instead:

cLastRow = Cells(Rows.Count, "A").End(xlUp).Row
For r = cLastRow To 1 Step -1
If InStr(1, Cells(r, "A"), "Starts:") 0 Then
Cells(r, "A").Select
ActiveCell.Offset(0, 8).Range("A1:E1").Select
Selection.Delete Shift:=xlToLeft
ActiveCell.Offset(0, -8).Range("A1:I1").Select
Selection.Cut Destination:=ActiveCell.Offset(0,
9).Range("A1:I1")
End If
Next r

Much better I think. Understand a little more about offsets now.

Cheers

Mark K Wrote:
Hi,

I'm having no problems with selecting and manipulating single cells
with variables but don't understand how to convert this to working with
Range. For example, in a macro I''ll find a row with the text "Starts:"
in column A. Working on any single cell (or complete row) referenced
from that start point isn't a problem, but if I want to work with more
than one cell, I do it one cell at a time because I can't figure out
how to select more than one using a Range with variables.

I currently use this to delete some cells (columns I to M) and then
move columns A to I to columns J to R.

cLastRow = Cells(Rows.Count, "A").End(xlUp).Row
For r = cLastRow To 1 Step -1
If InStr(1, Cells(r, "A"), "Starts:") 0 Then
Cells(r, "I").Select
Selection.Delete Shift:=xlToLeft
Selection.Delete Shift:=xlToLeft
Selection.Delete Shift:=xlToLeft
Selection.Delete Shift:=xlToLeft
Selection.Delete Shift:=xlToLeft
Selection.Cut Destination:=Cells(r, "R")
Cells(r, "H").Select
Selection.Cut Destination:=Cells(r, "Q")
Cells(r, "G").Select
Selection.Cut Destination:=Cells(r, "P")
Cells(r, "F").Select
Selection.Cut Destination:=Cells(r, "O")
Cells(r, "E").Select
Selection.Cut Destination:=Cells(r, "N")
Cells(r, "D").Select
Selection.Cut Destination:=Cells(r, "M")
Cells(r, "C").Select
Selection.Cut Destination:=Cells(r, "L")
Cells(r, "B").Select
Selection.Cut Destination:=Cells(r, "K")
Cells(r, "A").Select
Selection.Cut Destination:=Cells(r, "J")
End If
Next r

Very messy but it works.

I then use a similar procedure later to move the same range back to
column A (need to get them out of the way for some text to column
stuff). I know it can be simplified with a range, but how do I do it?



--
Mark K
------------------------------------------------------------------------
Mark K's Profile: http://www.excelforum.com/member.php...o&userid=14117
View this thread: http://www.excelforum.com/showthread...hreadid=573825

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
Now I'm Really Confused doss04 New Users to Excel 5 October 14th 08 04:38 AM
Confused about range names Busy John Excel Discussion (Misc queries) 3 February 1st 07 10:24 PM
confused by linking to Cells in Other Workbooks Jim May Excel Discussion (Misc queries) 1 August 8th 06 12:00 AM
Confused about formatting of contents and cells? ZZBC[_2_] Excel Programming 2 February 2nd 06 08:37 PM
confused... keepitcool Excel Programming 0 September 22nd 03 09:29 AM


All times are GMT +1. The time now is 04:37 PM.

Powered by vBulletin® Copyright ©2000 - 2025, Jelsoft Enterprises Ltd.
Copyright ©2004-2025 ExcelBanter.
The comments are property of their posters.
 

About Us

"It's about Microsoft Excel"