Replace the following line in your code

Worksheets("Input").Range("source_col:source_col").Copy _
Destination:=Worksheets("Output").Range("dest_col" & 1)

with

Worksheets("Input").Range(source_col & ":" & source_col).Copy _
Destination:=Worksheets("Output").Range(dest_col & 1)


Akhilesh Kumar Karna


On Thu, Jun 11, 2009 at 3:10 AM, Dustin <[email protected]> wrote:

>
> Hello Group,
>
> The code at the end of this post does not work, but I made it to be
> the best approximation of what I need. How it *should* work:
>
> The following is a map with header columns:
>
> G     H           I          J
> s       ID      ClientId        q
>
> col G holds the ORIGINAL column reference letter
> col H holds data (irrelevant here)
> col I holds data (irrelevant here)
> col J holds the DESTINATION column reference letter
>
> What I would like to happen, is to have a loop that goes through each
> row in columns G and J (this part I have working, no problem),
> and then for the values of those cells be the references for selecting
> a column.
>
> For instance. The first iteration of the loop chooses "s" as the
> variable "source_col" and "q" as the "dest_col"
>
> the lines following that attempt to copy the contents of column S and
> paste it into column Q (on their respective worksheets, input and
> output.)
>
> I cannot seem to get this reference to read correctly though. Any
> Thoughts? Thank you!!
>
> Dustin
>
>
>
> code:
> ********************************************************************
> Sub MoveColumns()
>
> Dim countnonblank As Integer, myRange As Range
> Set myRange = Columns("G:G")
> countnonblank = Application.WorksheetFunction.CountA(myRange)
> MsgBox countnonblank
>
> For i = 2 To countnonblank
> source_col = Range("G" & i).Value
> dest_col = Range("J" & i).Value
>
> Worksheets("Input").Range("source_col:source_col").Copy _
> Destination:=Worksheets("Output").Range("dest_col" & 1)
>
> Next
>
> End Sub
> ********************************************************************
>
> >
>

--~--~---------~--~----~------------~-------~--~----~
-------------------------------------------------------------------------------------
Some important links for excel users:
1. Excel and VBA Tutorials(Video and Text), Free add-ins downloads at 
http://www.excelitems.com
2. Excel tutorials at http://www.excel-macros.blogspot.com
3. Learn VBA Macros at http://www.vbamacros.blogspot.com
4. Excel Tips and Tricks at http://exceldailytip.blogspot.com
 

To post to this group, send email to [email protected]
If you find any spam message in the group, please send an email to:
Ayush Jain  @ [email protected] or
Ashish Jain @ [email protected]
-------------------------------------------------------------------------------------
-~----------~----~----~----~------~----~------~--~---

Reply via email to