PDA

View Full Version : Need Help With A Project.



vandel212
09-15-2008, 01:21 PM
I'm familiar with Visual Basic because I've taken classes at my school for it so i know the basic terminologies, but I have never edited a macro before and need some help.

With that said... What I am trying to do is to take cells from a excel 2007 spreadsheet, say A1 - G1, and copy them into a .txt file. Then I need to create a loop so that it copies the next 7 columns in row 1. So What I'm trying to figgure out is how to get the text in the cell from excel to a .txt file. Also what I can't figure out is how to increase the value of the columns because they are represented by letters so I don't think I can +1 to column A.

What may even work better is to just do 1 cell at a time, but none the less I would need to know how to increase the column letter for each pass.

If you need any more info I will be happy to reply. Thanks in advance.

MaximS
09-15-2008, 01:33 PM
you can increase columns/rows in the same time

Cells(i, j).Value

where "i" is row number and "j" is a collumn number

vandel212
09-15-2008, 01:47 PM
I'm not sure if I understand what you mean. how would i tell it to make it go from A1 to B1 for a loop?

CreganTur
09-15-2008, 01:54 PM
Welcome to the forum- alwasy good to see new members!

What' Maxim's trying to say is that you can use variables to stand in for your row/column values.

I've found that I need to use the Chr() function to get columns to work correctly.

Take the following code and paste it into a module in your workbook- be sure there are values in cells A1 and A2. After pasting in the code place your cursor anywhere in the Code and press F5 to make it run. This will grab the value of cell A1, and then increase the value of 'i' so it gets A2.

Sub Test()
Dim i As Integer
Dim x As Integer
i = 1
x = 1
For i = 1 To 2
Debug.Print Range(Chr(64 + x) & 1).Value
Next
End Sub

If you want to get something from column B then you would increase the value of x.

HTH:thumb

MaximS
09-15-2008, 02:00 PM
loop should look like

Sub MyString()

Dim MyString As String

MyString = ""

For j = 1 To 7
MyString = MyString & Cells(1, j).Value & " "
Next j
End Sub


where j = 1 to 7 means go from column A (1) to column G (7) and add values from it to make string
looking like: "xxx xxx xxxx xxxx xxxx xxxx xxxx".