PC Review


Reply
Thread Tools Rate Thread

beginner ColumnsQuestion b + 1 = c how?

 
 
Paul Isaak
Guest
Posts: n/a
 
      9th Nov 2006
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





 
Reply With Quote
 
 
 
 
Susan
Guest
Posts: n/a
 
      9th Nov 2006
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


 
Reply With Quote
 
=?Utf-8?B?R2FyeScncyBTdHVkZW50?=
Guest
Posts: n/a
 
      9th Nov 2006
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
>
>
>
>
>
>

 
Reply With Quote
 
excel.steve.kyle@gmail.com
Guest
Posts: n/a
 
      9th Nov 2006
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


 
Reply With Quote
 
=?Utf-8?B?Q2FybG9z?=
Guest
Posts: n/a
 
      9th Nov 2006
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
>
>
>
>
>
>

 
Reply With Quote
 
Paul Isaak
Guest
Posts: n/a
 
      9th Nov 2006
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" <(E-Mail Removed)> wrote in message
newsTI4h.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
>
>
>
>
>



 
Reply With Quote
 
 
 
Reply

Thread Tools
Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
Re: Beginner Bob Phillips Microsoft Excel Programming 0 4th Jan 2007 10:41 AM
No Class at ALL!!! beginner/beginner question =?Utf-8?B?S3VydCBTY2hyb2VkZXI=?= Microsoft ASP .NET 7 3rd Feb 2005 02:47 PM
Help for a beginner!.....PLEASE??? Tricia Microsoft Excel Misc 1 15th Jan 2004 06:51 PM
RIS beginner MAP Microsoft Windows 2000 Deployment 4 28th Dec 2003 11:10 PM
Beginner Help.... Mike Bell Microsoft ASP .NET 1 12th Jul 2003 07:18 AM


Features
 

Advertising
 

Newsgroups
 


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