Posts by VBAno0b

    Re: Checking worksheet names and renaming if duplicate found

    I have changed the code drastically now. I'm not sure if the code will check for the largest number of Imported (ie. find Imported2 instead of Imported1).. But it now looks like this:

    However, I get an error on this line:

    Range("O1").Select.Formula = "=Imported" & counter

    I don't understand why this won't run?

    Hi everyone! I do not have much experience in excel and would appreciated any help with my situation. My problem in excel right now is checking all the worksheet names and if one exists, then rename the current worksheet to WorksheetName1, with the next one being WorksheetName2, WorksheetName3 and so on.

    For example, right now, I name my worksheets as "Imported" using the following:

        Selection.Formula = "Imported"
        Selection.PasteSpecial Paste:=xlValues
        Application.CutCopyMode = False
        ActiveSheet.Name = Range("O1").Value
        Range("O1").Value = ""

    But I want to modify the above so it checks worksheet names already in the excel workbook and if another worksheet is already named "Imported", then the current worksheet will be renamed "Imported1".

    Also, my codes following that also functions based on the worksheet names. For example, in another Sub, I add another worksheet named "Graphs" and have it behind "Imported". But how do I make sure the data used to make "Graphs1" will come from "Imported1" (if "Imported" already exists). Code below:

    I know the code is probably really inefficient and looks horrible, but I just need to get it done. Inefficiency is the least of my concerns :)

    P.S. Extremely noob question: How do I automatically format the codes so it indents properly? And when an error occurs, how do I check which line is the problem? Thanks in advance!

    Re: Run-time error '91': Object variable or With block variable not set

    I've eliminated the variables and for each of the formulas with "" inside, I added another set of "" so it became """".

    Like so,

    Hi, I have very little idea of how to program in VBA but I've managed so far by consulting internet forums to obtain the following code to do what I need, but I am getting an error and I don't know what is wrong? Here is the code: