Wrox Programmer Forums
|
Excel VBA Discuss using VBA for Excel programming.
Welcome to the p2p.wrox.com Forums.

You are currently viewing the Excel VBA section of the Wrox Programmer to Programmer discussions. This is a community of software programmers and website developers including Wrox book authors and readers. New member registration was closed in 2019. New posts were shut off and the site was archived into this static format as of October 1, 2020. If you require technical support for a Wrox book please contact http://hub.wiley.com
 
Old January 26th, 2007, 11:54 AM
Registered User
 
Join Date: Jan 2007
Posts: 3
Thanks: 0
Thanked 0 Times in 0 Posts
Default Excel vba trouble

Hi All,

I am trying to write code, that looks in a text string in column a, it looks for a secific text, if true i want it to be a result in column n, but i am having problems. any help would be great.
here is my code so far

Sub Macro4()


    Dim a As Integer
    Sheets("Data").Select

    For a = 2 To Range("a65536").End(xlUp).Row
        If (InStr(1, Cells(a, 1).Value, "VLAB-Kerberos")) Then
        Cells(n, 1).Value = "VLAB"
        Else: Cells(n, 1).Value = ""
        End If
    Next
    ' MsgBox (InStr(1, Cells(2, 2), "abc", vbTextCompare))
End Sub

thanks Liam

 
Old January 27th, 2007, 06:00 AM
Friend of Wrox
 
Join Date: Oct 2003
Posts: 168
Thanks: 0
Thanked 0 Times in 0 Posts
Default

HI Liam,

You should specify variable n.

Your code is now:
Cells(n, 1).Value = "VLAB"
it means
Cells(0, 1).Value = "VLAB"

I you want the result in column C, you assign a value to variable n (n = 3) and if you want the result in the same row, your code should be
Cells(a,n).Value="VLAB"


-vemaju
 
Old January 29th, 2007, 05:59 AM
Registered User
 
Join Date: Jan 2007
Posts: 3
Thanks: 0
Thanked 0 Times in 0 Posts
Default

Hi
Thanks for your response, but I dont really understand it?? Can you explain further, or write the code?

Thanks - Liam

 
Old January 29th, 2007, 10:47 AM
Friend of Wrox
 
Join Date: Oct 2003
Posts: 168
Thanks: 0
Thanked 0 Times in 0 Posts
Default

Hi Liam,

This is the code

Sub Macro4()
    Dim a As Long
    Dim n As Byte
    'n is Column C. Change this to another column
    n = 3
    Sheets("Data").Select

    For a = 2 To Range("a65536").End(xlUp).Row
        If (InStr(1, Cells(a, 1), "VLAB-Kerberos") > 0) Then
            Cells(a, n).Value = "VLAB"
        Else
            Cells(a, n).Value = ""
        End If
    Next
End Sub

-vemaju
 
Old January 30th, 2007, 10:58 AM
Registered User
 
Join Date: Jan 2007
Posts: 3
Thanks: 0
Thanked 0 Times in 0 Posts
Default

Hi Vemaju

Thanks a million, it works a treat now!!

Liam






Similar Threads
Thread Thread Starter Forum Replies Last Post
Code works in Excel VBA but not Access VBA fossx Access VBA 2 May 21st, 2007 08:00 AM
Trouble hiding and unhiding columns in VBA jtmelb Excel VBA 0 February 14th, 2007 07:04 PM
Converting excel data to Access using excel VBA ShaileshShinde VB Databases Basics 1 April 26th, 2006 07:57 AM
Trouble putting data into Excel Drop Down List Arsi C# 2 October 26th, 2004 11:47 AM
Excel VBA to SQL & back to VBA edesousa Excel VBA 1 June 1st, 2004 02:39 AM





Powered by vBulletin®
Copyright ©2000 - 2020, Jelsoft Enterprises Ltd.
Copyright (c) 2020 John Wiley & Sons, Inc.