View Single Post
  #10   Report Post  
Posted to microsoft.public.excel.misc
nastech nastech is offline
external usenet poster
 
Posts: 383
Default Change Reference to Columns in a Macro

hi, thanks both for replies, not sure if I have to post twice to send, but
for this,
am finishing code base/basics before could get some pro-help with combining
this with another file macro-code.

(novice/ no macro experience) but some of.. 1. macro code needed to
automate small copy-paste task, sub to other sheet download task.

2. is a lock to keep from hitting button by accident / will use same button
for download ("X", later). missed getting clearing "Z" out of box after
copy-paste, but figure can get that myself, believe there was a macro making
tool in excel.

****
help is greatly appreciated. work ~2 full time jobs, was trying to get this
info all week. and.. haven't had chance to try/ look at closely yet.

here I :) would say darn, after all posts previous, missed putting in some
of info previously supplied, but imagine I can figure that out easy enough
with all that has been supplied.

would think items should be on same sheet (if a fault 13MB: constantly
fine-tuning out uneeded variables; my sheet is basically a 1 sheet setup for
now).
will follow-up with "work" with someone offline, after I get to that.. thanks.

previous info:
which all output, in sheet, as follows (related to script using below)..

DN6 in cell B1
DU:DU DT:DT B2 C2
EE:EY EF1 B3 C3
FE:FV FG:FX B4 C4
EC:ED FE:FF B5 C5

CK:CO CF B6 C6
CW:CW CG B7 C7




"JLatham" wrote:

I have 2 basic questions at this point:

#1 - are you wanting a formula solution or a code solution? I am under the
impression that you are looking for a code (macro) solution.

#2 - in your code you begin with a test for DN6 = "Z" - will you ever have
to look in any other cell for the "Z"?

I am going to rewrite yout first Sub (CommandButton1_Click) so that it gets
the ranges/addresses used from other cells on the same sheet and will post
that back later.


"Nastech" wrote:

hi, thanks for responses. sorry if questions sometimes vague. am not sure
what is pertinent vs. posting too much. (work on advanced items?.. slower
with some area's novice: spend much time to develope..).

:) not even sure if your answers apply.. new to scripting.. macro's, you
may need to tell me if your anwers apply to what doing, as not sure. thanks.


Will include script below that references, mostly columns. work-around is
for some kind of INDIRECT() reference to desired cells, from cells that will
not be moved, i.e. programming will never have to change.. ?? (not sure on
that), by use of either just typing the COLUMN LETTER reference in cells
listed (B2 C2, B3 C3 etc), OR with next formula use as a more "DYNAMIC"
response:

=SUBSTITUTE(SUBSTITUTE(CELL("address",$DU2),"$","" ),ROW(),"")&":"&SUBSTITUTE(SUBSTITUTE(CELL("addres s",$DU2),"$",""),ROW(),"")

gets: DU:DU
so if need any else such as quotes.. around "DU:DU", I can add to that
formula as well.

IF YOUR ANSWERS DO the same thing.. or apply to what doing you can let me
know, will work on but take some time for me to try.

PROBLEM: when add/ remove columns, have to manually change script.
SUBSTITUTE formula is work around.

Script using is:


Option Explicit
Private Sub CommandButton1_Click()
If Range("DN6").Value = "Z" Then
'1 col: copy Paste-Values to left 1 col
Columns("DU:DU").Select
Selection.Copy
Range("DT:DT").Select
ActiveSheet.PasteSpecial Format:=3, Link:=1, DisplayAsIcon:=False, _
IconFileName:=False
'22 col: (main, 21 col back up), COPY: Paste-Values to right 1 col
Columns("EE:EY").Select
Selection.Copy
Range("EF1").Select
ActiveSheet.PasteSpecial Format:=3, Link:=1, DisplayAsIcon:=False, _
IconFileName:=False
'20 col: (10 sets of 2), COPY: Paste-Values to right 2 cols
Columns("FE:FV").Select
Selection.Copy
Range("FG:FX").Select
ActiveSheet.PasteSpecial Format:=3, Link:=1, DisplayAsIcon:=False, _
IconFileName:=False
'double col: (1 set of 2), COPY: Paste-Values to different section
Columns("EC:ED").Select
Selection.Copy
Range("FE:FF").Select
ActiveSheet.PasteSpecial Format:=3, Link:=1, DisplayAsIcon:=False, _
IconFileName:=False
End If
End Sub
Private Sub Worksheet_Change(ByVal Target As Excel.Range)
With Target
If .Count 1 Then Exit Sub
If Target.Row < 130 Then Exit Sub
If Me.Cells(.Row, "A").Value = "." Then Exit Sub
'add "+" to blank spaces col A:
If Not Intersect(Me.Range("a:a"), .Cells) Is Nothing Then
Application.EnableEvents = False
.Value = Replace(.Value, " ", "+")
Application.EnableEvents = True
End If
'make column changes:
If Not Intersect(Me.Range("CK:CO"), .Cells) Is Nothing Then
Application.EnableEvents = False
'Destination:
With Me.Cells(.Row, "CF")
.NumberFormat = "dd"
.Value = Now
End With
Application.EnableEvents = True
End If
'make column changes:
If Not Intersect(Me.Range("CW:CW"), .Cells) Is Nothing Then
Application.EnableEvents = False
'Destination
With Me.Cells(.Row, "CG")
.NumberFormat = "dd"
.Value = Now
End With
Application.EnableEvents = True
End If
End With
End Sub






"JLatham" wrote:

If I understand you correctly, this concept should work.

Lets say that the column identifier you want to change is on a worksheet
named Sheet1 and it is in cell A1. Then your code can do something like
either of these examples:

Dim myColumns As String
myColumns = ThisWorkbook.Worksheets("Sheet1").Range("A1")
'assuming that cell A1 contained B:C then you dould do this

'you must activate the proper sheet first
Worksheets("Sheet2").Activate
Columns(myColumns).Select

and that would select columns A:C on Sheet2

You could even write it without "myColumns" this way
Worksheets("Sheet2").Activate
ThisWorkbook.Worksheets("Sheet1").Range("A1")
Columns(ThisWorkbook.Worksheets("Sheet1").Range("A 1")).Select

Hope this helps you with your problem.

"Nastech" wrote:

hi, is there a way to modify the reference to columns,
to be from a different single cell, such as INDIRECT..
within a macro / script? Thanks

the type of lines I want to reference a

Range("A1").Value
Columns("B:C").Select
Range("D:E").Select

Intersect(Me.Range("F:G"),
With Me.Cells(.Row, "H")