+ Reply to Thread
Results 1 to 4 of 4

Obtaining the first character of a cell value

Hybrid View

  1. #1
    Forum Contributor
    Join Date
    10-24-2012
    Location
    San Diego, USA
    MS-Off Ver
    Excel 2019
    Posts
    852

    Obtaining the first character of a cell value

    i have the below code, put together from guides and tutorial as best as i could, but it dont work, and need some help
    Sub CheckFileExists()
    
    'check if file exists and output results to message box
    
    With Worksheets("sheet3")
     newstring = Left(A1, 1)
     
    'newstring = Left(newstring, 1)
    'MsgBox , newstring
    End With
    If Dir(FolderRoot1 & CustomerName & Format(Today, "YY-MM-DD") & newstring & ("-map.pdf")) <> "" Then
        MsgBox newstring
    Else
        MsgBox newstring
    End If
    
    End Sub
    the cell is in A1 in SHEETS3, the first character letter is what i am trying to obtain.
    Last edited by chubbychub; 12-06-2023 at 01:43 PM.

  2. #2
    Forum Expert Arkadi's Avatar
    Join Date
    02-13-2014
    Location
    Smiths Falls, Ontario, Canada
    MS-Off Ver
    Office 365
    Posts
    5,059

    Re: Obtaining the first character of a cell value

    Try this inside the With Worksheets("Sheet3") section
    newstring = Left(.Range("A1").Value, 1)
    Please help by:

    Marking threads as closed once your issue is resolved. How? The Thread Tools at the top
    Any reputation (*) points appreciated. Not just by me, but by all those helping, so if you found someone's input useful, please take a second to click the * at the bottom left to let them know

    There are 10 kinds of people in this world... those who understand binary, and those who don't.

  3. #3
    Forum Contributor
    Join Date
    10-24-2012
    Location
    San Diego, USA
    MS-Off Ver
    Excel 2019
    Posts
    852

    Re: Obtaining the first character of a cell value

    thank you Arkadi that worked!

  4. #4
    Forum Expert Arkadi's Avatar
    Join Date
    02-13-2014
    Location
    Smiths Falls, Ontario, Canada
    MS-Off Ver
    Office 365
    Posts
    5,059

    Re: Obtaining the first character of a cell value

    Perfect! A cell address in a formula works in spreadsheets, but in VBA a cell (or group of cells) is a range... so A1 is Range("A1"), best to specify the sheet as well in my opinion, as you did

    With worksheets("sheet")
    .Range("address")
    end with

    or worksheets("sheet").Range("address")

+ Reply to Thread

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Similar Threads

  1. [SOLVED] Macro to rename cell content based on the starting character until found same character
    By oeyandyprawira in forum Excel Programming / VBA / Macros
    Replies: 8
    Last Post: 09-19-2015, 09:36 AM
  2. [SOLVED] Obtaining Last Six Digits in A Cell
    By Rasputin24 in forum Excel Programming / VBA / Macros
    Replies: 5
    Last Post: 11-24-2014, 03:50 PM
  3. Obtaining a Variable for a loop in the cell above
    By exdaver in forum Excel Programming / VBA / Macros
    Replies: 1
    Last Post: 06-25-2013, 01:03 PM
  4. Macro to find character and delete all text in cell after the character
    By SpencerRichman in forum Excel Programming / VBA / Macros
    Replies: 1
    Last Post: 02-01-2012, 06:08 PM
  5. Obtaining Cell Values from Worksheets
    By rclewis51 in forum Excel Formulas & Functions
    Replies: 4
    Last Post: 03-27-2009, 10:00 AM
  6. Obtaining The Functions Cell
    By BassMan449 in forum Excel Programming / VBA / Macros
    Replies: 7
    Last Post: 07-27-2007, 03:06 PM
  7. Obtaining a value and assigning to a cell
    By knowtrump in forum Excel Programming / VBA / Macros
    Replies: 2
    Last Post: 06-26-2007, 07:42 PM

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts

Search Engine Friendly URLs by vBSEO 3.6.0 RC 1