ExcelBanter

ExcelBanter (https://www.excelbanter.com/)
-   Excel Programming (https://www.excelbanter.com/excel-programming/)
-   -   beginner ColumnsQuestion b + 1 = c how? (https://www.excelbanter.com/excel-programming/377131-beginner-columnsquestion-b-1-%3D-c-how.html)

Paul Isaak

beginner ColumnsQuestion b + 1 = c how?
 
Forgive me, I'm very new to VBA for Excel

I want to use a for next loop to cycle through data in columns, but how do
I add one to the current column?

IE

A + 1 = B


I was pretty proud of myself when I made it work with rows, but the columns
have me stumped.

Paul
--
__________________________________

The Comedy & Juggling of Paul Isaak
http://www.funnyjuggler.com






Susan

beginner ColumnsQuestion b + 1 = c how?
 
you can use "offset" to move rows OR columns

activecell.offset(rows,columns).select

activecell.offset(0,1).select would move one column over.
<you wouldn't have to use .select, i just used it as an example.
susan


Paul Isaak wrote:
Forgive me, I'm very new to VBA for Excel

I want to use a for next loop to cycle through data in columns, but how do
I add one to the current column?

IE

A + 1 = B


I was pretty proud of myself when I made it work with rows, but the columns
have me stumped.

Paul
--
__________________________________

The Comedy & Juggling of Paul Isaak
http://www.funnyjuggler.com



Gary''s Student

beginner ColumnsQuestion b + 1 = c how?
 
This goes down column C and fills the first 10 cells with one more than the
value in column B:

Sub comedy_is_tough()
For i = 1 To 10
Cells(i, "C").Value = Cells(i, "B").Value + 1
Next
End Sub
--
Gary's Student


"Paul Isaak" wrote:

Forgive me, I'm very new to VBA for Excel

I want to use a for next loop to cycle through data in columns, but how do
I add one to the current column?

IE

A + 1 = B


I was pretty proud of myself when I made it work with rows, but the columns
have me stumped.

Paul
--
__________________________________

The Comedy & Juggling of Paul Isaak
http://www.funnyjuggler.com







[email protected]

beginner ColumnsQuestion b + 1 = c how?
 
You can use the ascii code to increment Letters


Chr(Asc("A") + 1)

returns "B"




~Steve


Paul Isaak wrote:
Forgive me, I'm very new to VBA for Excel

I want to use a for next loop to cycle through data in columns, but how do
I add one to the current column?

IE

A + 1 = B


I was pretty proud of myself when I made it work with rows, but the columns
have me stumped.

Paul
--
__________________________________

The Comedy & Juggling of Paul Isaak
http://www.funnyjuggler.com



Carlos

beginner ColumnsQuestion b + 1 = c how?
 
Hi,

I think it would be much easier if you turn into "matrix" notation. For
example, instead of referring to cells like this: "A1", refer to them like
this .Cells(1,1). This way you can `sum' columns. Otherwise, you could design
a function that maps letters to columns using the fact that every char has
its correspondign representation in ASCII code. For example, in one
application I used the following code to build cell formulas (like $A$1
+$A209, $B$1 +$B209, etc.).

Option Explicit
Public Function FirmToLetter(Firm As Long)
If Firm = 1 Then
FirmToLetter = Chr(66)
ElseIf 2 <= Firm And Firm < 19 Then
FirmToLetter = Chr(72 + Firm)
ElseIf 19 <= Firm And Firm < 45 Then
FirmToLetter = "A" & Chr(46 + Firm)
ElseIf 45 <= Firm And Firm < 71 Then
FirmToLetter = "B" & Chr(20 + Firm)
ElseIf 71 <= Firm And Firm < 97 Then
FirmToLetter = "C" & Chr(-6 + Firm)
ElseIf 97 <= Firm And Firm < 123 Then
FirmToLetter = "D" & Chr(-32 + Firm)
ElseIf 123 <= Firm And Firm < 149 Then
FirmToLetter = "E" & Chr(-58 + Firm)
ElseIf 149 <= Firm And Firm < 175 Then
FirmToLetter = "F" & Chr(-84 + Firm)
ElseIf 175 <= Firm And Firm < 201 Then
FirmToLetter = "G" & Chr(-110 + Firm)
ElseIf 201 <= Firm And Firm < 227 Then
FirmToLetter = "H" & Chr(-136 + Firm)
ElseIf 227 <= Firm And Firm < 249 Then
FirmToLetter = "I" & Chr(-162 + Firm)
Else
Call MsgBox("That number of firms exceeds Excel's number of columns!")
Exit Function
End If
End Function


--
Carlos


"Paul Isaak" wrote:

Forgive me, I'm very new to VBA for Excel

I want to use a for next loop to cycle through data in columns, but how do
I add one to the current column?

IE

A + 1 = B


I was pretty proud of myself when I made it work with rows, but the columns
have me stumped.

Paul
--
__________________________________

The Comedy & Juggling of Paul Isaak
http://www.funnyjuggler.com







Paul Isaak

beginner ColumnsQuestion b + 1 = c how?
 
Wow

Thanks for all the quick help on that!

Steve's answer made the most sense for my application, but I'll look at the
others to see if I can figure out the advantages of each.

I'm doing something like...

myColumn = "A"
for x = 1 to 50
if range(myColumn,1).value = "some date" then
do whatever
end if
myColumn = Chr(Asc(myColumn) + 1)
next x

I know it's a basic script, but I'm just starting to learn


Thanks again

Paul

--
__________________________________

The Comedy & Juggling of Paul Isaak
http://www.funnyjuggler.com



Toll Free - 1-877-852-4590
"Paul Isaak" wrote in message
news:pTI4h.285349$5R2.278674@pd7urf3no...
Forgive me, I'm very new to VBA for Excel

I want to use a for next loop to cycle through data in columns, but how
do I add one to the current column?

IE

A + 1 = B


I was pretty proud of myself when I made it work with rows, but the
columns have me stumped.

Paul
--
__________________________________

The Comedy & Juggling of Paul Isaak
http://www.funnyjuggler.com









All times are GMT +1. The time now is 05:13 AM.

Powered by vBulletin® Copyright ©2000 - 2025, Jelsoft Enterprises Ltd.
ExcelBanter.com