Home

VBA troubleshooting: "Object variable or With block variable not set" How do I fix this?

%3CLINGO-SUB%20id%3D%22lingo-sub-114792%22%20slang%3D%22en-US%22%3EVBA%20troubleshooting%3A%20%22Object%20variable%20or%20With%20block%20variable%20not%20set%22%20How%20do%20I%20fix%20this%3F%3C%2FLINGO-SUB%3E%3CLINGO-BODY%20id%3D%22lingo-body-114792%22%20slang%3D%22en-US%22%3E%3CP%20class%3D%22p1%22%3EI'm%20using%20Excel%20version%2015.38%20for%20Mac%20and%20I'm%20getting%20a%20runtime%20error%20that%20I%20don't%20know%20how%20to%20fix%20it.%20This%20macro%20worked%20perfectly%20for%20months%2C%20I%20stopped%20using%20this%20spreadsheet%20over%20the%20summer%2C%20and%20today%20when%20I%20go%20to%20use%20it%20again%2C%20it%20mysteriously%20won't%20work.%20When%20I%20try%20to%20run%20it%2C%20it%20gets%20stuck%20saying%20there's%20a%20runtime%20error%2091%26nbsp%3BObject%20variable%20or%20With%20block%20variable%20not%20set.%3CBR%20%2F%3E%3CBR%20%2F%3EIf%20I%20click%20on%20%22debug%22%2C%20the%20following%20code%20is%20highlighted%3A%3C%2FP%3E%3CP%20class%3D%22p1%22%3E%26nbsp%3B%3C%2FP%3E%3CP%20class%3D%22p1%22%3ESelection.Find(What%3A%3D%22visit%20amazon's%20%22%2C%20After%3A%3DActiveCell%2C%20LookIn%3A%3D%20_%3C%2FP%3E%3CP%20class%3D%22p1%22%3E%3CSPAN%20class%3D%22s1%22%3E%3CSPAN%20class%3D%22Apple-converted-space%22%3E%26nbsp%3B%20%26nbsp%3B%20%26nbsp%3B%20%26nbsp%3B%20%3C%2FSPAN%3E%3C%2FSPAN%3ExlFormulas%2C%20LookAt%3A%3DxlPart%2C%20SearchOrder%3A%3DxlByRows%2C%20SearchDirection%3A%3D%20_%3C%2FP%3E%3CP%20class%3D%22p1%22%3E%3CSPAN%20class%3D%22s1%22%3E%3CSPAN%20class%3D%22Apple-converted-space%22%3E%26nbsp%3B%20%26nbsp%3B%20%26nbsp%3B%20%26nbsp%3B%20%3C%2FSPAN%3E%3C%2FSPAN%3ExlNext%2C%20MatchCase%3A%3DFalse).Activate%3C%2FP%3E%3CP%20class%3D%22p1%22%3E%26nbsp%3B%3C%2FP%3E%3CP%20class%3D%22p1%22%3E%3CSPAN%3E(Attached%20screenshot%20is%20what%20the%20data%20looks%20like%20prior%20to%20running%20the%20macro.%26nbsp%3B%3C%2FSPAN%3EThe%20macro%20is%20supposed%20to%20remove%20punctuation%2C%20remove%20certain%20phrases%20etc.)%3CIMG%20src%3D%22https%3A%2F%2Fi.snag.gy%2Fyqh7Dd.jpg%22%20border%3D%220%22%20%2F%3E%3C%2FP%3E%3CP%20class%3D%22p1%22%3E%26nbsp%3B%3C%2FP%3E%3CP%20class%3D%22p1%22%3ECan%20any%20of%20you%20smart%20people%20tell%20me%20what's%20wrong%3F%26nbsp%3B%3CSPAN%3EI%20don't%20understand%20VBA%20code%20at%20all%20-%20this%20macro%20was%20created%20by%20recording%20me%20doing%20all%20this%20stuff%20manually%20-%20but%20I'm%20good%20at%20following%20directions%20%3A)%3C%2FSPAN%3E%3C%2FP%3E%3CP%20class%3D%22p1%22%3E%26nbsp%3B%3C%2FP%3E%3CP%20class%3D%22p1%22%3EFor%20what%20it's%20worth%2C%20here%20is%20the%20entire%20macro%20code%20from%20start%20to%20finish%3A%3CBR%20%2F%3E%3CBR%20%2F%3E%3C%2FP%3E%3CP%20class%3D%22p1%22%3E%3CSPAN%20class%3D%22s1%22%3ESub%3C%2FSPAN%3E%20step1_amazon_keywordprocessing()%3C%2FP%3E%3CP%20class%3D%22p2%22%3E'%3C%2FP%3E%3CP%20class%3D%22p2%22%3E'%20step1_amazon_keywordprocessing%20Macro%3C%2FP%3E%3CP%20class%3D%22p2%22%3E'%20Change%20to%20lower_Use%20data%20text%20to%20columns%20to%20get%20rid%20of%20%3A%20and%20(_get%20rid%20of%20Visit%20Amazon's_Get%20rid%20of%20page%3C%2FP%3E%3CP%20class%3D%22p2%22%3E'%3C%2FP%3E%3CP%20class%3D%22p2%22%3E'%20Keyboard%20Shortcut%3A%20Option%2BCmd%2Br%3C%2FP%3E%3CP%20class%3D%22p2%22%3E'%3C%2FP%3E%3CP%20class%3D%22p1%22%3E%3CSPAN%20class%3D%22Apple-converted-space%22%3E%26nbsp%3B%20%26nbsp%3B%20%3C%2FSPAN%3ERange(%22B1%22).Select%3C%2FP%3E%3CP%20class%3D%22p1%22%3E%3CSPAN%20class%3D%22Apple-converted-space%22%3E%26nbsp%3B%20%26nbsp%3B%20%3C%2FSPAN%3EActiveCell.FormulaR1C1%20%3D%20%22%3DLOWER(RC%5B-1%5D)%22%3C%2FP%3E%3CP%20class%3D%22p1%22%3E%3CSPAN%20class%3D%22Apple-converted-space%22%3E%26nbsp%3B%20%26nbsp%3B%20%3C%2FSPAN%3ERange(%22B1%22).Select%3C%2FP%3E%3CP%20class%3D%22p1%22%3E%3CSPAN%20class%3D%22Apple-converted-space%22%3E%26nbsp%3B%20%26nbsp%3B%20%3C%2FSPAN%3ESelection.AutoFill%20Destination%3A%3DRange(%22B1%3AB201%22)%2C%20Type%3A%3DxlFillDefault%3C%2FP%3E%3CP%20class%3D%22p1%22%3E%3CSPAN%20class%3D%22Apple-converted-space%22%3E%26nbsp%3B%20%26nbsp%3B%20%3C%2FSPAN%3ERange(%22B1%3AB201%22).Select%3C%2FP%3E%3CP%20class%3D%22p1%22%3E%3CSPAN%20class%3D%22Apple-converted-space%22%3E%26nbsp%3B%20%26nbsp%3B%20%3C%2FSPAN%3EColumns(%22B%3AB%22).Select%3C%2FP%3E%3CP%20class%3D%22p1%22%3E%3CSPAN%20class%3D%22Apple-converted-space%22%3E%26nbsp%3B%20%26nbsp%3B%20%3C%2FSPAN%3ESelection.Copy%3C%2FP%3E%3CP%20class%3D%22p1%22%3E%3CSPAN%20class%3D%22Apple-converted-space%22%3E%26nbsp%3B%20%26nbsp%3B%20%3C%2FSPAN%3EColumns(%22C%3AC%22).Select%3C%2FP%3E%3CP%20class%3D%22p1%22%3E%3CSPAN%20class%3D%22Apple-converted-space%22%3E%26nbsp%3B%20%26nbsp%3B%20%3C%2FSPAN%3ESelection.PasteSpecial%20Paste%3A%3DxlValues%2C%20Operation%3A%3DxlNone%2C%20SkipBlanks%3A%3D%20_%3C%2FP%3E%3CP%20class%3D%22p1%22%3E%3CSPAN%20class%3D%22Apple-converted-space%22%3E%26nbsp%3B%20%26nbsp%3B%20%26nbsp%3B%20%26nbsp%3B%20%3C%2FSPAN%3E%3CSPAN%20class%3D%22s1%22%3EFalse%3C%2FSPAN%3E%2C%20Transpose%3A%3D%3CSPAN%20class%3D%22s1%22%3EFalse%3C%2FSPAN%3E%3C%2FP%3E%3CP%20class%3D%22p1%22%3E%3CSPAN%20class%3D%22Apple-converted-space%22%3E%26nbsp%3B%20%26nbsp%3B%20%3C%2FSPAN%3EColumns(%22B%3AB%22).Select%3C%2FP%3E%3CP%20class%3D%22p1%22%3E%3CSPAN%20class%3D%22Apple-converted-space%22%3E%26nbsp%3B%20%26nbsp%3B%20%3C%2FSPAN%3EApplication.CutCopyMode%20%3D%20%3CSPAN%20class%3D%22s1%22%3EFalse%3C%2FSPAN%3E%3C%2FP%3E%3CP%20class%3D%22p1%22%3E%3CSPAN%20class%3D%22Apple-converted-space%22%3E%26nbsp%3B%20%26nbsp%3B%20%3C%2FSPAN%3ESelection.ClearContents%3C%2FP%3E%3CP%20class%3D%22p1%22%3E%3CSPAN%20class%3D%22Apple-converted-space%22%3E%26nbsp%3B%20%26nbsp%3B%20%3C%2FSPAN%3EColumns(%22A%3AA%22).Select%3C%2FP%3E%3CP%20class%3D%22p1%22%3E%3CSPAN%20class%3D%22Apple-converted-space%22%3E%26nbsp%3B%20%26nbsp%3B%20%3C%2FSPAN%3ESelection.ClearContents%3C%2FP%3E%3CP%20class%3D%22p1%22%3E%3CSPAN%20class%3D%22Apple-converted-space%22%3E%26nbsp%3B%20%26nbsp%3B%20%3C%2FSPAN%3ERange(%22C1%22).Select%3C%2FP%3E%3CP%20class%3D%22p1%22%3E%3CSPAN%20class%3D%22Apple-converted-space%22%3E%26nbsp%3B%20%26nbsp%3B%20%3C%2FSPAN%3ESelection.Copy%3C%2FP%3E%3CP%20class%3D%22p1%22%3E%3CSPAN%20class%3D%22Apple-converted-space%22%3E%26nbsp%3B%20%26nbsp%3B%20%3C%2FSPAN%3EColumns(%22A%3AA%22).Select%3C%2FP%3E%3CP%20class%3D%22p1%22%3E%3CSPAN%20class%3D%22Apple-converted-space%22%3E%26nbsp%3B%20%26nbsp%3B%20%3C%2FSPAN%3EColumns(%22C%3AC%22).Select%3C%2FP%3E%3CP%20class%3D%22p1%22%3E%3CSPAN%20class%3D%22Apple-converted-space%22%3E%26nbsp%3B%20%26nbsp%3B%20%3C%2FSPAN%3EApplication.CutCopyMode%20%3D%20%3CSPAN%20class%3D%22s1%22%3EFalse%3C%2FSPAN%3E%3C%2FP%3E%3CP%20class%3D%22p1%22%3E%3CSPAN%20class%3D%22Apple-converted-space%22%3E%26nbsp%3B%20%26nbsp%3B%20%3C%2FSPAN%3ESelection.Copy%3C%2FP%3E%3CP%20class%3D%22p1%22%3E%3CSPAN%20class%3D%22Apple-converted-space%22%3E%26nbsp%3B%20%26nbsp%3B%20%3C%2FSPAN%3EColumns(%22A%3AA%22).Select%3C%2FP%3E%3CP%20class%3D%22p1%22%3E%3CSPAN%20class%3D%22Apple-converted-space%22%3E%26nbsp%3B%20%26nbsp%3B%20%3C%2FSPAN%3EActiveSheet.Paste%3C%2FP%3E%3CP%20class%3D%22p1%22%3E%3CSPAN%20class%3D%22Apple-converted-space%22%3E%26nbsp%3B%20%26nbsp%3B%20%3C%2FSPAN%3EColumns(%22C%3AC%22).Select%3C%2FP%3E%3CP%20class%3D%22p1%22%3E%3CSPAN%20class%3D%22Apple-converted-space%22%3E%26nbsp%3B%20%26nbsp%3B%20%3C%2FSPAN%3EApplication.CutCopyMode%20%3D%20%3CSPAN%20class%3D%22s1%22%3EFalse%3C%2FSPAN%3E%3C%2FP%3E%3CP%20class%3D%22p1%22%3E%3CSPAN%20class%3D%22Apple-converted-space%22%3E%26nbsp%3B%20%26nbsp%3B%20%3C%2FSPAN%3ESelection.ClearContents%3C%2FP%3E%3CP%20class%3D%22p1%22%3E%3CSPAN%20class%3D%22Apple-converted-space%22%3E%26nbsp%3B%20%26nbsp%3B%20%3C%2FSPAN%3EColumns(%22A%3AA%22).Select%3C%2FP%3E%3CP%20class%3D%22p1%22%3E%3CSPAN%20class%3D%22Apple-converted-space%22%3E%26nbsp%3B%20%26nbsp%3B%20%3C%2FSPAN%3ESelection.TextToColumns%20Destination%3A%3DRange(%22A1%22)%2C%20DataType%3A%3DxlDelimited%2C%20_%3C%2FP%3E%3CP%20class%3D%22p1%22%3E%3CSPAN%20class%3D%22Apple-converted-space%22%3E%26nbsp%3B%20%26nbsp%3B%20%26nbsp%3B%20%26nbsp%3B%20%3C%2FSPAN%3ETextQualifier%3A%3DxlDoubleQuote%2C%20ConsecutiveDelimiter%3A%3D%3CSPAN%20class%3D%22s1%22%3EFalse%3C%2FSPAN%3E%2C%20Tab%3A%3D%3CSPAN%20class%3D%22s1%22%3ETrue%3C%2FSPAN%3E%2C%20_%3C%2FP%3E%3CP%20class%3D%22p1%22%3E%3CSPAN%20class%3D%22Apple-converted-space%22%3E%26nbsp%3B%20%26nbsp%3B%20%26nbsp%3B%20%26nbsp%3B%20%3C%2FSPAN%3ESemicolon%3A%3D%3CSPAN%20class%3D%22s1%22%3EFalse%3C%2FSPAN%3E%2C%20Comma%3A%3D%3CSPAN%20class%3D%22s1%22%3EFalse%3C%2FSPAN%3E%2C%20Space%3A%3D%3CSPAN%20class%3D%22s1%22%3EFalse%3C%2FSPAN%3E%2C%20Other%3A%3D%3CSPAN%20class%3D%22s1%22%3ETrue%3C%2FSPAN%3E%2C%20OtherChar%20_%3C%2FP%3E%3CP%20class%3D%22p1%22%3E%3CSPAN%20class%3D%22Apple-converted-space%22%3E%26nbsp%3B%20%26nbsp%3B%20%26nbsp%3B%20%26nbsp%3B%20%3C%2FSPAN%3E%3A%3D%22%3A%22%2C%20FieldInfo%3A%3DArray(Array(1%2C%201)%2C%20Array(2%2C%201))%3C%2FP%3E%3CP%20class%3D%22p1%22%3E%3CSPAN%20class%3D%22Apple-converted-space%22%3E%26nbsp%3B%20%26nbsp%3B%20%3C%2FSPAN%3EColumns(%22B%3AH%22).Select%3C%2FP%3E%3CP%20class%3D%22p1%22%3E%3CSPAN%20class%3D%22Apple-converted-space%22%3E%26nbsp%3B%20%26nbsp%3B%20%3C%2FSPAN%3ESelection.ClearContents%3C%2FP%3E%3CP%20class%3D%22p1%22%3E%3CSPAN%20class%3D%22Apple-converted-space%22%3E%26nbsp%3B%20%26nbsp%3B%20%3C%2FSPAN%3EColumns(%22A%3AA%22).Select%3C%2FP%3E%3CP%20class%3D%22p1%22%3E%3CSPAN%20class%3D%22Apple-converted-space%22%3E%26nbsp%3B%20%26nbsp%3B%20%3C%2FSPAN%3ESelection.TextToColumns%20Destination%3A%3DRange(%22A1%22)%2C%20DataType%3A%3DxlDelimited%2C%20_%3C%2FP%3E%3CP%20class%3D%22p1%22%3E%3CSPAN%20class%3D%22Apple-converted-space%22%3E%26nbsp%3B%20%26nbsp%3B%20%26nbsp%3B%20%26nbsp%3B%20%3C%2FSPAN%3ETextQualifier%3A%3DxlDoubleQuote%2C%20ConsecutiveDelimiter%3A%3D%3CSPAN%20class%3D%22s1%22%3EFalse%3C%2FSPAN%3E%2C%20Tab%3A%3D%3CSPAN%20class%3D%22s1%22%3ETrue%3C%2FSPAN%3E%2C%20_%3C%2FP%3E%3CP%20class%3D%22p1%22%3E%3CSPAN%20class%3D%22Apple-converted-space%22%3E%26nbsp%3B%20%26nbsp%3B%20%26nbsp%3B%20%26nbsp%3B%20%3C%2FSPAN%3ESemicolon%3A%3D%3CSPAN%20class%3D%22s1%22%3EFalse%3C%2FSPAN%3E%2C%20Comma%3A%3D%3CSPAN%20class%3D%22s1%22%3EFalse%3C%2FSPAN%3E%2C%20Space%3A%3D%3CSPAN%20class%3D%22s1%22%3EFalse%3C%2FSPAN%3E%2C%20Other%3A%3D%3CSPAN%20class%3D%22s1%22%3ETrue%3C%2FSPAN%3E%2C%20OtherChar%20_%3C%2FP%3E%3CP%20class%3D%22p1%22%3E%3CSPAN%20class%3D%22Apple-converted-space%22%3E%26nbsp%3B%20%26nbsp%3B%20%26nbsp%3B%20%26nbsp%3B%20%3C%2FSPAN%3E%3A%3D%22(%22%2C%20FieldInfo%3A%3DArray(1%2C%201)%3C%2FP%3E%3CP%20class%3D%22p1%22%3E%3CSPAN%20class%3D%22Apple-converted-space%22%3E%26nbsp%3B%20%26nbsp%3B%20%3C%2FSPAN%3EColumns(%22B%3AH%22).Select%3C%2FP%3E%3CP%20class%3D%22p1%22%3E%3CSPAN%20class%3D%22Apple-converted-space%22%3E%26nbsp%3B%20%26nbsp%3B%20%3C%2FSPAN%3ESelection.ClearContents%3C%2FP%3E%3CP%20class%3D%22p1%22%3E%3CSPAN%20class%3D%22Apple-converted-space%22%3E%26nbsp%3B%20%26nbsp%3B%20%3C%2FSPAN%3EColumns(%22A%3AA%22).Select%3C%2FP%3E%3CP%20class%3D%22p3%22%3E%3CSPAN%20class%3D%22s2%22%3E%3CSPAN%20class%3D%22Apple-converted-space%22%3E%26nbsp%3B%20%26nbsp%3B%20%3C%2FSPAN%3E%3C%2FSPAN%3ESelection.Find(What%3A%3D%22visit%20amazon's%20%22%2C%20After%3A%3DActiveCell%2C%20LookIn%3A%3D%20_%3C%2FP%3E%3CP%20class%3D%22p3%22%3E%3CSPAN%20class%3D%22s2%22%3E%3CSPAN%20class%3D%22Apple-converted-space%22%3E%26nbsp%3B%20%26nbsp%3B%20%26nbsp%3B%20%26nbsp%3B%20%3C%2FSPAN%3E%3C%2FSPAN%3ExlFormulas%2C%20LookAt%3A%3DxlPart%2C%20SearchOrder%3A%3DxlByRows%2C%20SearchDirection%3A%3D%20_%3C%2FP%3E%3CP%20class%3D%22p3%22%3E%3CSPAN%20class%3D%22s2%22%3E%3CSPAN%20class%3D%22Apple-converted-space%22%3E%26nbsp%3B%20%26nbsp%3B%20%26nbsp%3B%20%26nbsp%3B%20%3C%2FSPAN%3E%3C%2FSPAN%3ExlNext%2C%20MatchCase%3A%3DFalse).Activate%3C%2FP%3E%3CP%20class%3D%22p1%22%3E%3CSPAN%20class%3D%22Apple-converted-space%22%3E%26nbsp%3B%20%26nbsp%3B%20%3C%2FSPAN%3EExecuteExcel4Macro%20_%3C%2FP%3E%3CP%20class%3D%22p1%22%3E%3CSPAN%20class%3D%22Apple-converted-space%22%3E%26nbsp%3B%20%26nbsp%3B%20%26nbsp%3B%20%26nbsp%3B%20%3C%2FSPAN%3E%22FORMULA.REPLACE(%22%22visit%20amazon's%20%22%22%2C%22%22%22%22%2C2%2C1%2CFALSE%2CFALSE%2C%2CFALSE%2CFALSE%2CFALSE%2CFALSE)%22%3C%2FP%3E%3CP%20class%3D%22p1%22%3E%3CSPAN%20class%3D%22Apple-converted-space%22%3E%26nbsp%3B%20%26nbsp%3B%20%3C%2FSPAN%3ESelection.Find(What%3A%3D%22%20page%22%2C%20After%3A%3DActiveCell%2C%20LookIn%3A%3DxlFormulas%2C%20_%3C%2FP%3E%3CP%20class%3D%22p1%22%3E%3CSPAN%20class%3D%22Apple-converted-space%22%3E%26nbsp%3B%20%26nbsp%3B%20%26nbsp%3B%20%26nbsp%3B%20%3C%2FSPAN%3ELookAt%3A%3DxlPart%2C%20SearchOrder%3A%3DxlByRows%2C%20SearchDirection%3A%3DxlNext%2C%20_%3C%2FP%3E%3CP%20class%3D%22p1%22%3E%3CSPAN%20class%3D%22Apple-converted-space%22%3E%26nbsp%3B%20%26nbsp%3B%20%26nbsp%3B%20%26nbsp%3B%20%3C%2FSPAN%3EMatchCase%3A%3D%3CSPAN%20class%3D%22s1%22%3EFalse%3C%2FSPAN%3E).Activate%3C%2FP%3E%3CP%20class%3D%22p1%22%3E%3CSPAN%20class%3D%22Apple-converted-space%22%3E%26nbsp%3B%20%26nbsp%3B%20%3C%2FSPAN%3EExecuteExcel4Macro%20_%3C%2FP%3E%3CP%20class%3D%22p1%22%3E%3CSPAN%20class%3D%22Apple-converted-space%22%3E%26nbsp%3B%20%26nbsp%3B%20%26nbsp%3B%20%26nbsp%3B%20%3C%2FSPAN%3E%22FORMULA.REPLACE(%22%22%20page%22%22%2C%22%22%22%22%2C2%2C1%2CFALSE%2CFALSE%2C%2CFALSE%2CFALSE%2CFALSE%2CFALSE)%22%3C%2FP%3E%3CP%20class%3D%22p4%22%3EEnd%20Sub%3C%2FP%3E%3CP%20class%3D%22p1%22%3E%3CBR%20%2F%3EThank-you%20in%20advance%20to%20anyone%20who%20can%20help%20me%20with%20this%20-%20I%20really%20appreciate%20it!%20%3A)%3C%2FP%3E%3CP%20class%3D%22p1%22%3E%26nbsp%3B%3C%2FP%3E%3C%2FLINGO-BODY%3E%3CLINGO-LABS%20id%3D%22lingo-labs-114792%22%20slang%3D%22en-US%22%3E%3CLINGO-LABEL%3EExcel%20on%20Mac%3C%2FLINGO-LABEL%3E%3CLINGO-LABEL%3EMacros%20%26amp%3B%20VBA%3C%2FLINGO-LABEL%3E%3C%2FLINGO-LABS%3E%3CLINGO-SUB%20id%3D%22lingo-sub-382569%22%20slang%3D%22en-US%22%3ERe%3A%20VBA%20troubleshooting%3A%20%22Object%20variable%20or%20With%20block%20variable%20not%20set%22%20How%20do%20I%20fix%20thi%3C%2FLINGO-SUB%3E%3CLINGO-BODY%20id%3D%22lingo-body-382569%22%20slang%3D%22en-US%22%3E%3CP%3EJust%20leaving%20this%20response%20here%20in%20case%20someone%20finds%20this%20useful.%20I%20was%20facing%20a%20similar%20issue%20when%20running%20a%20macro.%20I%20was%20trying%20to%20run%20the%20macro%20on%20a%20recently%20downloaded%20file%20and%20it%20kept%20throwing%20the%20Runtime%20Error%2091.%20Enabling%20Editing%20(clicking%20on%20Enable%20Editing)%20fixed%20the%20issue%20for%20me.%26nbsp%3B%3C%2FP%3E%3C%2FLINGO-BODY%3E%3CLINGO-SUB%20id%3D%22lingo-sub-355396%22%20slang%3D%22en-US%22%3ERe%3A%20VBA%20troubleshooting%3A%20%22Object%20variable%20or%20With%20block%20variable%20not%20set%22%20How%20do%20I%20fix%20thi%3C%2FLINGO-SUB%3E%3CLINGO-BODY%20id%3D%22lingo-body-355396%22%20slang%3D%22en-US%22%3E%3CP%3E%3CA%20href%3D%22https%3A%2F%2Ftechcommunity.microsoft.com%2Ft5%2Fuser%2Fviewprofilepage%2Fuser-id%2F287540%22%20target%3D%22_blank%22%3E%40Gijs1%3C%2FA%3E%26nbsp%3Bplease%20start%20your%20own%20thread.%20Feel%20free%20to%20message%20me%20the%20link.%20Also%2C%20your%20code%20looks%20fine%20and%20you%20shouldn't%20be%20getting%20that%20error.%20You%20would%2C%20however%2C%20need%20two%20references%20(Tools%20%26gt%3B%20References...)%20Microsoft%20HTML%20Object%20Library%20and%20Microsoft%20Internet%20Controls.%3C%2FP%3E%3C%2FLINGO-BODY%3E%3CLINGO-SUB%20id%3D%22lingo-sub-353865%22%20slang%3D%22en-US%22%3ERe%3A%20VBA%20troubleshooting%3A%20%22Object%20variable%20or%20With%20block%20variable%20not%20set%22%20How%20do%20I%20fix%20thi%3C%2FLINGO-SUB%3E%3CLINGO-BODY%20id%3D%22lingo-body-353865%22%20slang%3D%22en-US%22%3E%3CP%3EHey%20guys%2C%3C%2FP%3E%3CP%3E%26nbsp%3B%3C%2FP%3E%3CP%3EI%20am%20trying%20to%20fill-in%20data%20in%20a%20website%20with%20VBA%2C%20but%20I%20am%20getting%20a%20run%20time%20error%2091.%20I%20have%20the%20idea%20that%20there%20is%20an%20error%20due%20to%20auto-complete%2C%20but%20I%20am%20not%20100%25%20sure.%3C%2FP%3E%3CP%3EThe%20website%20is%20to%20calculate%20travel%20time%2C%20the%20value%20is%20(Dutch)%20travel%20data.%3C%2FP%3E%3CP%3E%26nbsp%3B%3C%2FP%3E%3CP%3EWho%20can%20help%20me%3F%26nbsp%3B%26nbsp%3B%3C%2FP%3E%3CP%3E%3CA%20href%3D%22https%3A%2F%2Ftechcommunity.microsoft.com%2Ft5%2Fuser%2Fviewprofilepage%2Fuser-id%2F19137%22%20target%3D%22_blank%22%3E%40Zack%20Barresse%3C%2FA%3E%3F%3C%2FP%3E%3CP%3EVBA%20Code%3A%3C%2FP%3E%3CP%3E--------------------------------------------------------------------------------------%3C%2FP%3E%3CP%3E%26nbsp%3B%3C%2FP%3E%3CP%3ESub%20GetHTMLDocument()%3C%2FP%3E%3CP%3EDim%20IE%20As%20New%20SHDocVw.InternetExplorer%3CBR%20%2F%3EDim%20HTMLDoc%20As%20MSHTML.HTMLDocument%3CBR%20%2F%3EDim%20HTMLInput%20As%20MSHTML.IHTMLElement%3CBR%20%2F%3EDim%20HTMLButtons%20As%20MSHTML.IHTMLElementCollection%3CBR%20%2F%3EDim%20HTMLButton%20As%20MSHTML.IHTMLElement%3CBR%20%2F%3E%3CBR%20%2F%3EIE.Visible%20%3D%20True%3CBR%20%2F%3EIE.navigate%20%22%3CA%20href%3D%22https%3A%2F%2Fwww.anwb.nl%2Fverkeer%2Frouteplanner%22%20target%3D%22_blank%22%20rel%3D%22nofollow%20noopener%20noreferrer%20noopener%20noreferrer%22%3Ehttps%3A%2F%2Fwww.anwb.nl%2Fverkeer%2Frouteplanner%3C%2FA%3E%22%3CBR%20%2F%3E%3CBR%20%2F%3EDo%20While%20IE.ReadyState%20%26lt%3B%26gt%3B%20READYSTATE_COMPLETE%3CBR%20%2F%3ELoop%3CBR%20%2F%3E%3CBR%20%2F%3ESet%20HTMLDoc%20%3D%20IE.Document%3CBR%20%2F%3ESet%20HTMLInput%20%3D%20HTMLDoc.getElementById(%22routing-input-address-field-0%22)%3CBR%20%2F%3EHTMLInput.Value%20%3D%20%229711NA%22%3CBR%20%2F%3E%3CBR%20%2F%3E%3CBR%20%2F%3EEnd%20Sub%3C%2FP%3E%3CP%3E-----------------------------------------------------------------------------------%3C%2FP%3E%3C%2FLINGO-BODY%3E%3CLINGO-SUB%20id%3D%22lingo-sub-123345%22%20slang%3D%22en-US%22%3ERe%3A%20VBA%20troubleshooting%3A%20%22Object%20variable%20or%20With%20block%20variable%20not%20set%22%20How%20do%20I%20fix%20thi%3C%2FLINGO-SUB%3E%3CLINGO-BODY%20id%3D%22lingo-body-123345%22%20slang%3D%22en-US%22%3EThat's%20awesome!%20We%20do%20love%20saving%20people%20time.%20%3B)%3CBR%20%2F%3E%3CBR%20%2F%3EVery%20much%20appreciate%20the%20follow-up.%20It%20helps%20us%20know%20that%20what%20we%20do%20is%20worth%20it.%3C%2FLINGO-BODY%3E%3CLINGO-SUB%20id%3D%22lingo-sub-123315%22%20slang%3D%22en-US%22%3ERe%3A%20VBA%20troubleshooting%3A%20%22Object%20variable%20or%20With%20block%20variable%20not%20set%22%20How%20do%20I%20fix%20thi%3C%2FLINGO-SUB%3E%3CLINGO-BODY%20id%3D%22lingo-body-123315%22%20slang%3D%22en-US%22%3E%3CP%3EOkay%2C%20awesome%20news!%20Thanks%20to%20all%20your%20help%20Zack%2C%20I%20got%20the%20second%20macro%20to%20do%20what%20I%20want%20it%20to!%20Holy%20cow%20-%20this%20is%20beyond%20amazing%20since%20it%20will%20save%20me%20HOURS%20of%20repetitive%20manual%20labour%20replacing%20symbols%20and%20prohibited%20words%20with%20spaces%20or%20flat-out%20nothing.%3CBR%20%2F%3E%3CBR%20%2F%3EI%20thought%20I'd%20posted%20another%20questions%20about%20how%20I%20got%20stuck%2C%20but%20I%20don't%20see%20it%20here.%20I%20kept%20playing%20around%20with%20the%20problem%20and%20managed%20to%20fix%20it%20despite%20being%20clueless%20haha%20So%20if%20that%20new%20question%20from%20today%20DOES%20show%20up%2C%20you%20can%20ignore%20it.%3CBR%20%2F%3E%3CBR%20%2F%3EThanks%20again!!!%20%3AD%3C%2FP%3E%3C%2FLINGO-BODY%3E%3CLINGO-SUB%20id%3D%22lingo-sub-123306%22%20slang%3D%22en-US%22%3ERe%3A%20VBA%20troubleshooting%3A%20%22Object%20variable%20or%20With%20block%20variable%20not%20set%22%20How%20do%20I%20fix%20thi%3C%2FLINGO-SUB%3E%3CLINGO-BODY%20id%3D%22lingo-body-123306%22%20slang%3D%22en-US%22%3E%3CP%3EOkay%2C%20I'm%20back%20%3AD%3CBR%20%2F%3E%3CBR%20%2F%3ESo%20this%20is%20what%20I%20tried%20to%20create%20based%20on%20the%20above%20info%2C%20previous%20posts%20you've%20shared%2C%20and%20some%20Googling%3A%3CBR%20%2F%3E%3CBR%20%2F%3E(What%20I%20want%20it%20to%20do%20is%20to%20find%20and%20replace%20certain%20characters%20and%20words%20I%20don't%20want%2C%20but%20to%20ONLY%20do%20this%20on%20the%20sheet%20I'm%20currently%20looking%20at.%20And%20if%20it%20doesn't%20find%20the%20character%20it%20just%20looked%20for%20(will%20happen%20often)%2C%20I%20want%20it%20to%20skip%20ahead%20to%20the%20next%20one%20listed%20in%20the%20code.)%3CBR%20%2F%3E%3CBR%20%2F%3E%3C%2FP%3E%3CPRE%3ESub%20Sher_step2_amazon_keywordprocessing_find_and_replace_stuff()%0A'%0A'%20Sher_step2_amazon_keywordprocessing_find_and_replace_stuff%20Macro%0A%0A'%20Change%20to%20lower_find%20and%20replace%20prohibited%20symbols%20and%20words%0A'%0ADim%20ReplaceSheet%20As%20Worksheet%0ADim%20ReplaceRange%20As%20Range%0A%0ASet%20ReplaceSheet%20%3D%20ThisWorkbook.Worksheets(%22Sheet1%22)%0ASet%20ReplaceRange%20%3D%20ReplaceSheet.Range(%22A2%22%2C%20ReplaceSheet.Cells(ReplaceSheet.Rows.Count%2C%20%22A%22).End(xlUp))%0A%0AReplaceRange.Replace%20What%3A%3D%22!%22%2C%20Replacement%3A%3D%22%22%2C%20LookAt%3A%3DxlPart%0AOn%20Error%20Resume%20Next%0A%0AReplaceRange.Replace%20What%3A%3D%22%40%22%2C%20Replacement%3A%3D%22at%22%2C%20LookAt%3A%3DxlPart%0AOn%20Error%20Resume%20Next%0A%0AReplaceRange.Replace%20What%3A%3D%22%23%22%2C%20Replacement%3A%3D%22%22%2C%20LookAt%3A%3DxlPart%0AOn%20Error%20Resume%20Next%0A%0AReplaceRange.Replace%20What%3A%3D%22%24%22%2C%20Replacement%3A%3D%22%22%2C%20LookAt%3A%3DxlPart%0AOn%20Error%20Resume%20Next%0A%0AReplaceRange.Replace%20What%3A%3D%22%25%22%2C%20Replacement%3A%3D%22percent%22%2C%20LookAt%3A%3DxlPart%0AOn%20Error%20Resume%20Next%0A%0AReplaceRange.Replace%20What%3A%3D%22%5E%22%2C%20Replacement%3A%3D%22%22%2C%20LookAt%3A%3DxlPart%0AOn%20Error%20Resume%20Next%0A%0AReplaceRange.Replace%20What%3A%3D%22%26amp%3B%22%2C%20Replacement%3A%3D%22and%22%2C%20LookAt%3A%3DxlPart%0AOn%20Error%20Resume%20Next%0A%0AReplaceRange.Replace%20What%3A%3D%22%26lt%3B%22%2C%20Replacement%3A%3D%22%22%2C%20LookAt%3A%3DxlPart%0AOn%20Error%20Resume%20Next%0A%0AReplaceRange.Replace%20What%3A%3D%22%26gt%3B%22%2C%20Replacement%3A%3D%22%22%2C%20LookAt%3A%3DxlPart%0AOn%20Error%20Resume%20Next%0A%0AReplaceRange.Replace%20What%3A%3D%22-%20%22%2C%20Replacement%3A%3D%22%20%22%2C%20LookAt%3A%3DxlPart%0AOn%20Error%20Resume%20Next%0A%0AReplaceRange.Replace%20What%3A%3D%22-%22%2C%20Replacement%3A%3D%22%20%22%2C%20LookAt%3A%3DxlPart%0AOn%20Error%20Resume%20Next%0A%0AReplaceRange.Replace%20What%3A%3D%22%20%20%22%2C%20Replacement%3A%3D%22%20%22%2C%20LookAt%3A%3DxlPart%0AOn%20Error%20Resume%20Next%0A%0AReplaceRange.Replace%20What%3A%3D%22.%20%22%2C%20Replacement%3A%3D%22%22%2C%20LookAt%3A%3DxlPart%0AOn%20Error%20Resume%20Next%0A%0AReplaceRange.Replace%20What%3A%3D%22.%22%2C%20Replacement%3A%3D%22%22%2C%20LookAt%3A%3DxlPart%0AOn%20Error%20Resume%20Next%0A%0AReplaceRange.Replace%20What%3A%3D%22%20%20%22%2C%20Replacement%3A%3D%22%20%22%2C%20LookAt%3A%3DxlPart%0AOn%20Error%20Resume%20Next%0A%0AReplaceRange.Replace%20What%3A%3D%22%2F%22%2C%20Replacement%3A%3D%22%20%22%2C%20LookAt%3A%3DxlPart%0AOn%20Error%20Resume%20Next%0A%0AReplaceRange.Replace%20What%3A%3D%22%2C%22%2C%20Replacement%3A%3D%22%22%2C%20LookAt%3A%3DxlPart%0AOn%20Error%20Resume%20Next%0A%0AReplaceRange.Replace%20What%3A%3D%22%E2%80%9C%22%2C%20Replacement%3A%3D%22%22%2C%20LookAt%3A%3DxlPart%0AOn%20Error%20Resume%20Next%0A%0AReplaceRange.Replace%20What%3A%3D%22%E2%80%9C%22%2C%20Replacement%3A%3D%22%22%2C%20LookAt%3A%3DxlPart%0AOn%20Error%20Resume%20Next%0A%0AReplaceRange.Replace%20What%3A%3D%22%E2%80%9D%22%2C%20Replacement%3A%3D%22%22%2C%20LookAt%3A%3DxlPart%0AOn%20Error%20Resume%20Next%0A%0AReplaceRange.Replace%20What%3A%3D%22%E2%80%94%22%2C%20Replacement%3A%3D%22%20%22%2C%20LookAt%3A%3DxlPart%0AOn%20Error%20Resume%20Next%0A%0AReplaceRange.Replace%20What%3A%3D%22%C2%AE%22%2C%20Replacement%3A%3D%22%22%2C%20LookAt%3A%3DxlPart%0AOn%20Error%20Resume%20Next%0A%0AReplaceRange.Replace%20What%3A%3D%22Kindle%22%2C%20Replacement%3A%3D%22%22%2C%20LookAt%3A%3DxlPart%0AOn%20Error%20Resume%20Next%0A%0AEnd%20Sub%3C%2FPRE%3E%3CP%3EBut%20I%20got%20stumped%20on%20the%20following%3A%3CBR%20%2F%3E%3CBR%20%2F%3E1.%20As%20written%2C%20the%20macro%20appears%20to%20do%20it's%20thing%20only%20on%20a%20sheet%20of%20my%20workbook%20called%20%22Sheet1%22%20(which%20I%20don't%20want%20it%20to%20do).%20What%20I%20DO%20want%20is%20for%20it%20to%20do%20its%20thing%20only%20on%20whatever%20sheet%20I'm%20currently%20working%20on%20regardless%20of%20the%20name.%20(Not%20all%20sheets%20in%20the%20workbook%20though...%20only%20the%20one%20sheet%20I'm%20looking%20at).%20%3A)%3CBR%20%2F%3E%3CBR%20%2F%3EIf%20I%20delete%20the%20line%20of%20code%20that%20references%20%22sheet1%22%2C%20I%20get%20an%20error%20when%20I%20try%20to%20run%20the%20macro.%20If%20I%20cave%20and%20decide%20that%20fine%2C%20I'll%20tell%20it%20to%20run%20on%20a%20specific%20sheet%2C%20and%20I%20replace%20%22sheet1%22%20with%20the%20name%20of%20the%20sheet%20I%20want%20it%20to%20run%20on%20right%20now%20(ExperimentWithNewMacro)%2C%20I%20get%20a%20runtime%20error%20(Runtime%20error%209.%20Subscript%20out%20of%20range.)%20-%20if%20I%20click%20on%20%22Debug%22%2C%20it%20highlights%20this%20row%20of%20code%3A%3C%2FP%3E%3CPRE%3ESet%20ReplaceSheet%20%3D%20ThisWorkbook.Worksheets(%22ExperimentWithNewMacro%22)%3C%2FPRE%3E%3CP%3EI%20tried%20fiddling%20around%20with%20it%2C%20Googling%2C%20tweaking%20things%20etc...%20but%20couldn't%20get%20it%20to%20work.%20I%20figure%20I%20must%20be%20missing%20something%2C%20and%20I'm%20crossing%20my%20fingers%20that%20it'll%20be%20quick%20and%20obvious%20for%20you%20to%20see%20where%20I%20went%20wrong%20%3A)%3CBR%20%2F%3E%3CBR%20%2F%3E%3CBR%20%2F%3E%3C%2FP%3E%3C%2FLINGO-BODY%3E%3CLINGO-SUB%20id%3D%22lingo-sub-117398%22%20slang%3D%22en-US%22%3ERe%3A%20VBA%20troubleshooting%3A%20%22Object%20variable%20or%20With%20block%20variable%20not%20set%22%20How%20do%20I%20fix%20thi%3C%2FLINGO-SUB%3E%3CLINGO-BODY%20id%3D%22lingo-body-117398%22%20slang%3D%22en-US%22%3EYou're%20amazing%20for%20explaining%20all%20that%20-%20thank-you%20so%20much!%20I'm%20going%20to%20try%20it%20%3AD%3C%2FLINGO-BODY%3E%3CLINGO-SUB%20id%3D%22lingo-sub-115596%22%20slang%3D%22en-US%22%3ERe%3A%20VBA%20troubleshooting%3A%20%22Object%20variable%20or%20With%20block%20variable%20not%20set%22%20How%20do%20I%20fix%20thi%3C%2FLINGO-SUB%3E%3CLINGO-BODY%20id%3D%22lingo-body-115596%22%20slang%3D%22en-US%22%3E%3CP%3EReally%20close!%20The%20'RangeToWorkWith'%20is%20a%20Range%20object%20variable.%20So%20it%20can%20be%20any%20Range.%20For%20example...%3C%2FP%3E%3CP%3ERange(%22A1%22)%3C%2FP%3E%3CP%3E...or...%3C%2FP%3E%3CP%3E%3CBR%20%2F%3EDim%20RangeToWorkWith%20As%20Range%3CBR%20%2F%3ESet%20RangeToWorkWith%20%3D%20Range(%22A1%22)%3C%2FP%3E%3CP%3E%26nbsp%3B%3C%2FP%3E%3CP%3EIn%20the%20latter%2C%20'RangeToWorkWith'%20is%20now%20the%20same%20as%20Range(%22A1%22).%20The%20benefit%20of%20a%20variable%20is%20you%20can%20set%20it%20to%20whatever%20you%20want%2C%20and%20most%20importantly%20make%20them%20dynamic.%3C%2FP%3E%3CP%3E%26nbsp%3B%3C%2FP%3E%3CP%3EThe%20%22LookAt%22%20parameter%20of%20the%20Find%20or%20Replace%20method%20should%20be%20either%20xlPart%20or%20xlWhole%2C%20both%20part%20of%20the%20'XlLookAt'%20class%20of%20constants%20(which%20may%20be%20a%20little%20above%20your%20head%20at%20this%20point%2C%20but%20that's%20ok%20-%20immersion!).%20This%20says%20whether%20you%20want%20to%20look%20at%20the%20entire%20contents%20of%20the%20cell%20for%20the%20What%20parameter.%20In%20your%20case%20it%20should%20be%20xlPart.%3C%2FP%3E%3CP%3E%26nbsp%3B%3C%2FP%3E%3CP%3ESo%2C%20let's%20say%20you%20want%20to%20do%20all%20of%20this%20in%20column%20A.%20For%20me%2C%20I%20don't%20want%20to%20look%20at%20the%20whole%20column%2C%20because%20that's%20a%20LOT%20of%20cells%2C%20and%20I'm%20probably%20using%20a%20fraction%20of%20them.%20Also%2C%20let's%20say%20we%20have%20a%20header%20in%20row%201.%20So%20data%20starts%20on%20row%202%20and%20goes%20down%20an%20unknown%20number%20of%20rows.%20This%20is%20called%20a%20dynamic%20range%2C%20because%20it%20may%20not%20always%20be%20the%20same%20size%2C%20and%20is%20why%20a%20recorded%20macro%20may%20not%20work%20so%20well%20as%20it%20hard-codes%20the%20range%20address%20into%20the%20Range%20object.%3C%2FP%3E%3CP%3E%26nbsp%3B%3C%2FP%3E%3CPRE%3EDim%20ReplaceSheet%20As%20Worksheet%0ADim%20ReplaceRange%20As%20Range%0A%0ASet%20ReplaceSheet%20%3D%20ThisWorkbook.Worksheets(%22Sheet1%22)%0ASet%20ReplaceRange%20%3D%20ReplaceSheet.Range(%22A2%22%2C%20ReplaceSheet.Cells(ReplaceSheet.Rows.Count%2C%20%22A%22).End(xlUp))%0A%0AReplaceRange.Replace%20What%3A%3D%22!%22%2C%20Replacement%3A%3D%22%22%2C%20LookAt%3A%3DxlPart%0AReplaceRange.Replace%20What%3A%3D%22-%22%2C%20Replacement%3A%3D%22%20%22%2C%20LookAt%3A%3DxlPart%3C%2FPRE%3E%3CP%3EWith%20the%20above%20code%2C%20it%20doesn't%20matter%20if%20your%20data%20is%20in%20A2%3AA10%2C%20or%20A2%3AA1000%2C%20it%20will%20work%20on%20that%20data%20range.%20It%20basically%20looks%20at%20the%20bottom-most%20cell%20in%20that%20column%20and%20goes%20up%20until%20it%20finds%20data%20(the%20keyboard%20shortcut%20equivalent%20is%2C%20from%20the%20bottom%20of%20the%20sheet%2C%20press%20CTRL%20%2B%20Up%20Arrow).%26nbsp%3B%20Then%20it%20uses%20that%20range%20with%20the%20Replace%20method.%3C%2FP%3E%3CP%3E%26nbsp%3B%3C%2FP%3E%3CP%3EAnother%20added%20benefit%20of%20using%20a%20variable%20(properly%20scoped)%20is%20you%20get%20intellisense%20on%20that%20object.%20Since%20I%20declared%20the%20variable%20of%20a%20Range%20type%2C%20when%20you%20type%20that%20variable%20name%20and%20press%20period%2C%20you%20see%20a%20drop-down%20list%20of%20all%20methods%20and%20properties%20associated%20with%20that%20object.%20Methods%20have%20the%20little%20green%20icon%2C%20properties%20have%20the%20little%20card%20with%20a%20hand%20on%20it.%20Methods%26nbsp%3B%3CEM%3Edo%20something%3C%2FEM%3E%2C%20and%20may%20or%20may%20not%20take%20parameters%20passed%20to%20it%20(we're%20passing%20three%20parameters%20in%20the%20above%20code).%20Properties%20let%20us%20read%20(and%20sometimes%20write)%26nbsp%3Bdata%20to%20that%20property.%20A%20property%20can%20be%20values%20(i.e.%20text%2C%20numbers%2C%20dates)%20or%20objects%20(i.e.%20Range%2C%20Shape%2C%20Worksheet%2C%20Workbook).%20And%20hence%20commenses%20your%20crash%20course%20into%20Object%20Oriented%20Programming%20(OOP)!%20%3A)%3C%2FP%3E%3CP%3E%26nbsp%3B%3C%2FP%3E%3CP%3EI%20don't%20mind%20answering%20any%20question%20you%20might%20have.%20Post%20away!%3C%2FP%3E%3C%2FLINGO-BODY%3E%3CLINGO-SUB%20id%3D%22lingo-sub-115265%22%20slang%3D%22en-US%22%3ERe%3A%20VBA%20troubleshooting%3A%20%22Object%20variable%20or%20With%20block%20variable%20not%20set%22%20How%20do%20I%20fix%20thi%3C%2FLINGO-SUB%3E%3CLINGO-BODY%20id%3D%22lingo-body-115265%22%20slang%3D%22en-US%22%3E%3CP%3Ere%3A%20%22%3CSPAN%3EI%20wasn't%20sure%20what%20your%20Excel4Macro%20was%20supposed%20to%20be%20doing%22%3CBR%20%2F%3E%3CBR%20%2F%3EHa%2C%20neither%20am%20I!%20That's%20what%20you%20get%20when%20non-technie%20uses%20%22record%20macro%22%20lol%3CBR%20%2F%3E%3CBR%20%2F%3Ere%3A%20%3CEM%3E%22%3C%2FEM%3E%3C%2FSPAN%3E%3CEM%3Eif%20it's%20just%20replacing%20values%2C%20you%20can%20do%20that%20in%20one%20fell%20swoop%20too%3A%3C%2FEM%3E%3C%2FP%3E%3CP%3E%3CEM%3E%26nbsp%3B%3C%2FEM%3E%3C%2FP%3E%3CPRE%3E%3CEM%3ERangeToWorkWith.Replace%20What%3A%3D%22This%22%2C%20Replacement%3A%3D%22That%22%2C%20LookAt%3A%3DxlPart%3C%2FEM%3E%3C%2FPRE%3E%3CP%3E%3CEM%3EThe%20benefit%20for%20this%20is%2C%20not%20only%20is%20it%20taking%20care%20of%20two%20lines%20in%20one%20fell%20swoop%2C%20but%20it%20won't%20throw%20an%20error%20like%20the%20Find%20method%20will%2C%20so%20no%20need%20to%20wrap%20it%20in%20error%20handling.%3C%2FEM%3E%3CBR%20%2F%3E%3CSPAN%3E%3CBR%20%2F%3EAhh%2C%20cool.%20I'm%20going%20to%20play%20with%20that%20-%20because%20yes%2C%20it's%20nothing%20more%20than%20replacing%20values.%3CBR%20%2F%3E%3CBR%20%2F%3EFor%20syntax%2C%26nbsp%3Bsay%20I%20wanted%20it%20to%20replace%20all%20%22!%22%20in%20column%20A%20with%20%22%22%20(i.e.%20erase%20the%20!%20and%20replace%20it%20with%20nothing)%2C%20and%20then%20replace%20all%20%22-%22%20in%20column%20A%20with%20%22%20%22%20(i.e.%20replace%20a%20dash%20with%20a%20single%20space)...%20how%20would%20I%20write%20that%20using%20that%20type%20of%20code%3F%20I%20can%20guess%20all%20sorts%20of%20potential%20ways%20to%20%22fill%20in%20the%20blanks%22%2C%20but%26nbsp%3Bdon't%20know%20which%20one%20is%20correct...%20for%20the%20exclamation%20mark%2C%20for%20example...%3CBR%20%2F%3E%3CBR%20%2F%3E%3C%2FSPAN%3E%3C%2FP%3E%3CP%3E%3CSPAN%3EOption%201%3A%3CBR%20%2F%3E%3C%2FSPAN%3E%3C%2FP%3E%3CP%3E%26nbsp%3B%3C%2FP%3E%3CP%3E%3CSPAN%3ERangeToWorkWith.Replace%20What%3A%3D%22!%22%2C%20Replacement%3A%3D%22%22%2C%20LookAt%3A%3DA%3C%2FSPAN%3E%3C%2FP%3E%3CP%3E%26nbsp%3B%3C%2FP%3E%3CP%3E%3CSPAN%3EOption%202%3C%2FSPAN%3E%3C%2FP%3E%3CPRE%3EA.Replace%20What%3A%3D%22!%22%2C%20Replacement%3A%3D%22%22%2C%20LookAt%3A%3DA%3CBR%20%2F%3E%3CBR%20%2F%3EOption%203%3A%3CBR%20%2F%3E%3CBR%20%2F%3E%3C%2FPRE%3E%3CPRE%3ERange(A1).Replace%20What%3A%3D%22!%22%2C%20Replacement%3A%3D%22%22%2C%20LookAt%3A%3DA1%3CBR%20%2F%3E%3CBR%20%2F%3E%3C%2FPRE%3E%3CP%3ESomething%20else%3F%26nbsp%3B%3CBR%20%2F%3E%3CBR%20%2F%3ESorry...%20I%20realize%20this%20must%20be%20insanely%20basic%20to%20you%20since%20you%20know%20what%20you're%20doing%20hehe%26nbsp%3B%20And%20if%20you're%20tired%20of%20answering%20questions%2C%20that's%20cool%20too%20-%20the%20information%20you've%20already%20provided%20has%20been%20very%20helpful!%3C%2FP%3E%3C%2FLINGO-BODY%3E%3CLINGO-SUB%20id%3D%22lingo-sub-115247%22%20slang%3D%22en-US%22%3ERe%3A%20VBA%20troubleshooting%3A%20%22Object%20variable%20or%20With%20block%20variable%20not%20set%22%20How%20do%20I%20fix%20thi%3C%2FLINGO-SUB%3E%3CLINGO-BODY%20id%3D%22lingo-body-115247%22%20slang%3D%22en-US%22%3E%3CP%3EVery%20happy%20to%20help!%20%3A)%3C%2FP%3E%3CP%3E%26nbsp%3B%3C%2FP%3E%3CP%3EI'm%20not%20sure%20about%20Mac%2C%20but%20I%20don't%20think%20they%20have%20the%20F-keys%20on%20their%20keyboards%20and%20it's%20typically%20a%20PC%20thing.%20I%20use%20the%20VBE%20(Visual%20Basic%20Editor)%20keyboard%20shortcuts%20all%20the%20time.%20Huge%20time%20savers.%3C%2FP%3E%3CP%3E%26nbsp%3B%3C%2FP%3E%3CP%3EI%20wasn't%20sure%20what%20your%20Excel4Macro%20was%20supposed%20to%20be%20doing%2C%20but%20if%20it's%20just%20replacing%20values%2C%20you%20can%20do%20that%20in%20one%20fell%20swoop%20too%3A%3C%2FP%3E%3CP%3E%26nbsp%3B%3C%2FP%3E%3CPRE%3ERangeToWorkWith.Replace%20What%3A%3D%22This%22%2C%20Replacement%3A%3D%22That%22%2C%20LookAt%3A%3DxlPart%3C%2FPRE%3E%3CP%3EThe%20benefit%20for%20this%20is%2C%20not%20only%20is%20it%20taking%20care%20of%20two%20lines%20in%20one%20fell%20swoop%2C%20but%20it%20won't%20throw%20an%20error%20like%20the%20Find%20method%20will%2C%20so%20no%20need%20to%20wrap%20it%20in%20error%20handling.%3C%2FP%3E%3CP%3E%26nbsp%3B%3C%2FP%3E%3CP%3EAs%20long%20as%20we're%20talking%20about%20error%20handling%2C%20it%20should%20be%20noted%20this%20is%20the%20least%20preferred%20method%20for%20handling%20errors.%20The%20first%20is%20to%20take%20logical%20action%20in%20your%20code%20to%20prevent%20known%20errors%20from%20forming.%20The%20next%20would%20be%20trapping%20errors%20-%20performing%20some%20kind%20of%20check%20if%20an%20error%20was%20processed%2C%20like%20%22If%20Err.Number%20%26lt%3B%26gt%3B%200%22.%3C%2FP%3E%3CP%3E%26nbsp%3B%3C%2FP%3E%3CP%3EThanks%20for%20the%20detailed%20response.%20Have%20a%20great%20day!%3C%2FP%3E%3CP%3E%26nbsp%3B%3C%2FP%3E%3C%2FLINGO-BODY%3E%3CLINGO-SUB%20id%3D%22lingo-sub-115231%22%20slang%3D%22en-US%22%3ERe%3A%20VBA%20troubleshooting%3A%20%22Object%20variable%20or%20With%20block%20variable%20not%20set%22%20How%20do%20I%20fix%20thi%3C%2FLINGO-SUB%3E%3CLINGO-BODY%20id%3D%22lingo-body-115231%22%20slang%3D%22en-US%22%3E%3CP%3EThank-you%20SO%20much%20for%20doing%20that%20Zack%20-%20I%20can't%20tell%20you%20how%20much%20I%20appreciate%20you%20taking%20the%20time%20%3A)%20I%20learned%20some%20new%20things%20from%20what%20you%20said%20that%20will%20come%20in%20handy%20over%20the%20long%20term.%20Plus%2C%20it%20was%20informative%20to%20see%20your%20cleaner%20version%20of%20the%20macro%20code%20and%20I%20intend%20to%20study%20it%20until%20I%20understand%20what%20it's%20doing.%3CBR%20%2F%3E%3CBR%20%2F%3E(Writing%20all%20the%20rest%20of%20this%20partly%20in%20case%20someone%20else%20comes%20along%20who%20finds%20this%20useful...)%3CBR%20%2F%3E%3CBR%20%2F%3EI%20went%20through%20the%20code%20line%20by%20line%20as%20you%20said%2C%20and%20figured%20out%20that%20the%20recorded%20code%20was%20getting%20stuck%20on%20the%20part%20where%20it%20had%20to%20find%20%22Visit%20Amazon's%20%22%20because%20in%20this%20particular%20set%20of%20data%2C%20that%20wasn't%20on%20there.%20Then%20the%20same%20issue%20would%20happen%20when%20it%20was%20supposed%20to%20find%20%22%20page%22%20because%20that%20wasn't%20in%20this%20set%20of%20data%20either.%3CBR%20%2F%3E%3CBR%20%2F%3E(For%20non-techies%20like%20me%20who%20might%20read%20this%3A%20F8%20didn't%20work%20on%20my%20Mac%20(maybe%20it's%20a%20Windows-only%20shortcut%3F)%2C%20but%20using%20the%20little%20button%20in%20the%20VBA%20editor%20that%20looked%20like%20a%20down%20error%20pointing%20to%20a%20dot%2C%20which%20said%20%22step%20into%22%20if%20I%20hovered%20over%20it%2C%20seems%20to%20do%20the%20same%20thing%20as%20F8%20was%20supposed%20to%20do.)%3CBR%20%2F%3E%3CBR%20%2F%3ESo%20I%20saw%20what%20you%20meant%20when%20you%20said%20%22%3CSPAN%3EIf%20nothing%20is%20found%2C%20an%20error%20is%20thrown.%22%3C%2FSPAN%3E%3CBR%20%2F%3E%3CBR%20%2F%3ESo%20if%20I%20created%20a%20test%20line%20that%20DID%20contain%20%22Visit%20Amazon's%20Test%20Author%20page%22%2C%20the%20macro%20with%20the%20messy%20recorded%20code%20ran%20fine.%3CBR%20%2F%3E%3CBR%20%2F%3EBut%20since%20I%20don't%20want%20to%20do%20the%20work%20of%20adding%20that%20every%20time%20I%20want%20to%20clean%20up%20my%20data%20with%20the%20macro%20(just%20in%20case%20it%20doesn't%20contain%20that%20stuff)%2C%20I%20added%20%22On%20Error%20Resume%20Next%22%20before%20each%20section%20of%20the%20macro%20that%20was%20supposed%20to%20find%20and%20replace%20since%20the%20stuff%20it's%20looking%20for%20won't%20always%20be%20found%20and%20that's%20no%20big%20deal.%26nbsp%3B%3CBR%20%2F%3E%3CBR%20%2F%3ENow%20the%20macro%20works%20despite%20the%20messy%20code.%3CBR%20%2F%3E%3CBR%20%2F%3EMy%20next%20job%20is%20to%20play%20with%20YOUR%20code.%3CBR%20%2F%3E%3CBR%20%2F%3EAND%2C%20by%20the%20way%2C%20this%20%22%3CSPAN%3E%22%3C%2FSPAN%3E%3CSPAN%3EOn%20Error%20Resume%20Next%22%20that%20you%20added%20to%20your%20cleaner%20code%20is%20seriously%20a%20game%20changer%20since%20now%20I%20can%20make%20the%20macro%20also%20look%20for%20symbols%20and%20punctuation%20marks%2C%20and%20replace%20those%20with%20nothing%20-%20this%20is%20HUGE%20for%20me%20since%20prior%20to%20your%20response%2C%20I%20couldn't%20get%20the%20macro%20to%20do%20that%20for%20me%20(which%20I%20now%20understand%20is%20because%20it%20would%20get%20stuck%20if%20the%20thing%20it%20was%20looking%20for%20wasn't%20present).%20WAHOO!%20This%20new%20knowledge%20will%20save%20me%20loads%20of%20tedious%2C%20repetitive%20manual%20fixing%20up%20in%20future%20since%20now%20I%20can%20make%20a%20macro%20do%20it%20all%20FOR%20me%20without%20getting%20itself%20stuck.%20THANK-YOU%20SO%20MUCH!!!%26nbsp%3B%3C%2FSPAN%3E%3CBR%20%2F%3E%3CBR%20%2F%3Ere%3A%20%22%3CSPAN%3EAlso%2C%20there%20is%20no%20worksheet%20referenced%20for%20the%20ranges%2C%20so%20it%20will%20ALWAYS%20run%20on%20the%20ActiveSheet.%22%3CBR%20%2F%3E%3CBR%20%2F%3E%3C%2FSPAN%3EYes%2C%20this%20is%20okay%20for%20my%20purposes%20-%20but%20thanks%20for%20pointing%20that%20out!%3CBR%20%2F%3E%3CBR%20%2F%3EI'm%20going%20to%20go%20play%20with%20the%20code%20more%20now.%20This%20non-techie%20is%20so%20flipping%20happy%20with%20this%20you%20have%20no%20idea%20%3AD%3CBR%20%2F%3E%3CBR%20%2F%3E%3CBR%20%2F%3E%3C%2FP%3E%3C%2FLINGO-BODY%3E%3CLINGO-SUB%20id%3D%22lingo-sub-115105%22%20slang%3D%22en-US%22%3ERe%3A%20VBA%20troubleshooting%3A%20%22Object%20variable%20or%20With%20block%20variable%20not%20set%22%20How%20do%20I%20fix%20thi%3C%2FLINGO-SUB%3E%3CLINGO-BODY%20id%3D%22lingo-body-115105%22%20slang%3D%22en-US%22%3E%3CP%3EThat%20code%20will%20definitely%20fail.%20You're%20using%20the%20Selection%20object%20to%20find%20something%20after%20the%20ActiveCell.%20If%20nothing%20is%20found%2C%20an%20error%20is%20thrown.%20Overall%20it's%20very%20messy%20code.%20The%20macro%20recorder%20makes%20sure%20of%20that.%20But%2C%20it%20does%20make%20a%20great%20starting%20place!%3C%2FP%3E%3CP%3EIt%20looks%20like%20you%20took%20some%20repetitive%20actions%20in%20the%20recorded%20code.%20I'm%20not%20100%25%20that%20I%20followed%20everything%2C%20but%20I%20removed%20all%20of%20the%20Select%20methods%20you%20called%2C%20which%20aren't%20needed%20at%20all.%20Also%2C%20there%20is%20no%20worksheet%20referenced%20for%20the%20ranges%2C%20so%20it%20will%20ALWAYS%20run%20on%20the%20ActiveSheet.%20If%20you%20are%20always%20going%20to%20run%20this%20code%20on%20this%20worksheet%2C%20then%20it%20won't%20be%20a%20problem.%3C%2FP%3E%3CP%3EHere%20is%20the%20code%3A%3C%2FP%3E%3CP%3E%26nbsp%3B%3C%2FP%3E%3CPRE%3ESub%20step1_amazon_keywordprocessing()%0A'%0A'%20step1_amazon_keywordprocessing%20Macro%0A'%20Change%20to%20lower_Use%20data%20text%20to%20columns%20to%20get%20rid%20of%20%3A%20and%20(_get%20rid%20of%20Visit%20Amazon's_Get%20rid%20of%20page%0A'%0A'%20Keyboard%20Shortcut%3A%20Option%2BCmd%2Br%0A'%0ARange(%22B1%3AB201%22).FormulaR1C1%20%3D%20%22%3DLOWER(RC%5B-1%5D)%22%0AColumns(%22B%3AB%22).Copy%0AColumns(%22C%3AC%22).PasteSpecial%20Paste%3A%3DxlValues%0AApplication.CutCopyMode%20%3D%20False%0AColumns(%22A%3AB%22).ClearContents%0A%0AColumns(%22C%3AC%22).Copy%20Columns(%22A%3AA%22)%0AColumns(%22C%3AC%22).ClearContents%0AApplication.CutCopyMode%20%3D%20False%0A%0AColumns(%22A%3AA%22).TextToColumns%20Destination%3A%3DRange(%22A1%22)%2C%20DataType%3A%3DxlDelimited%2C%20_%0ATextQualifier%3A%3DxlDoubleQuote%2C%20ConsecutiveDelimiter%3A%3DFalse%2C%20Tab%3A%3DTrue%2C%20_%0ASemicolon%3A%3DFalse%2C%20Comma%3A%3DFalse%2C%20Space%3A%3DFalse%2C%20Other%3A%3DTrue%2C%20OtherChar%20_%0A%3A%3D%22%3A%22%2C%20FieldInfo%3A%3DArray(Array(1%2C%201)%2C%20Array(2%2C%201))%0A%0AColumns(%22B%3AH%22).ClearContents%0A%0AColumns(%22A%3AA%22).TextToColumns%20Destination%3A%3DRange(%22A1%22)%2C%20DataType%3A%3DxlDelimited%2C%20_%0ATextQualifier%3A%3DxlDoubleQuote%2C%20ConsecutiveDelimiter%3A%3DFalse%2C%20Tab%3A%3DTrue%2C%20_%0ASemicolon%3A%3DFalse%2C%20Comma%3A%3DFalse%2C%20Space%3A%3DFalse%2C%20Other%3A%3DTrue%2C%20OtherChar%20_%0A%3A%3D%22(%22%2C%20FieldInfo%3A%3DArray(1%2C%201)%0A%0AColumns(%22B%3AH%22).ClearContents%0A%0AColumns(%22A%3AA%22).Find(What%3A%3D%22visit%20amazon's%20%22%2C%20After%3A%3DActiveCell%2C%20LookIn%3A%3D%20_%0AxlFormulas%2C%20LookAt%3A%3DxlPart%2C%20SearchOrder%3A%3DxlByRows%2C%20SearchDirection%3A%3D%20_%0AxlNext%2C%20MatchCase%3A%3DFalse).Activate%0A%0AExecuteExcel4Macro%20%22FORMULA.REPLACE(%22%22visit%20amazon's%20%22%22%2C%22%22%22%22%2C2%2C1%2CFALSE%2CFALSE%2C%2CFALSE%2CFALSE%2CFALSE%2CFALSE)%22%0A%3CBR%20%2F%3EOn%20Error%20Resume%20Next%0AColumns(%22A%3AA%22).Find(What%3A%3D%22%20page%22%2C%20After%3A%3DRange(%22A1%22)%2C%20LookIn%3A%3DxlFormulas%2C%20_%0ALookAt%3A%3DxlPart%2C%20SearchOrder%3A%3DxlByRows%2C%20SearchDirection%3A%3DxlNext%2C%20_%0AMatchCase%3A%3DFalse).Activate%3CBR%20%2F%3EOn%20Error%20Goto%200%0A%0AExecuteExcel4Macro%20%22FORMULA.REPLACE(%22%22%20page%22%22%2C%22%22%22%22%2C2%2C1%2CFALSE%2CFALSE%2C%2CFALSE%2CFALSE%2CFALSE%2CFALSE)%22%0A%0AEnd%20Sub%3C%2FPRE%3E%3CP%3EI%20would%20recommend%20stepping%20through%20your%20code%20the%20first%20time%2C%20until%20you%20know%20it's%20working%20right.%20To%20do%20that%2C%20just%20put%20your%20cursor%20anywhere%20in%20this%20routine%20(to%20make%20it%20the%20active%20routine)%20and%20the%20F8%20key%20will%20step%20through%20each%20line%20of%20code.%20Tapping%20the%20F8%20key%20will%20execute%20a%20single%20line%20of%20code%20at%20a%20time.%20The%20yellow%20highlighted%20line%20is%20the%20one%20which%20will%20run%20when%20you%20press%20F8.%3C%2FP%3E%3CP%3E%26nbsp%3B%3C%2FP%3E%3CP%3EAlso%2C%20I%20added%20bare-minimum%20error%20handling%20to%20your%20Find%20method.%20This%20will%20ensure%20it%20doesn't%20bomb%20when%20executing%20that%20line.%20More%20importantly%2C%20I%20took%20out%20the%20Selection%20object%20you%20used%2C%20and%20replaced%20ActiveCell%20with%26nbsp%3BRange(%22A1%22).%3C%2FP%3E%3CP%3E%26nbsp%3B%3C%2FP%3E%3CP%3EHTH%3C%2FP%3E%3CP%3E%26nbsp%3B%3C%2FP%3E%3C%2FLINGO-BODY%3E
Sheralyn G
Occasional Contributor

I'm using Excel version 15.38 for Mac and I'm getting a runtime error that I don't know how to fix it. This macro worked perfectly for months, I stopped using this spreadsheet over the summer, and today when I go to use it again, it mysteriously won't work. When I try to run it, it gets stuck saying there's a runtime error 91 Object variable or With block variable not set.

If I click on "debug", the following code is highlighted:

 

Selection.Find(What:="visit amazon's ", After:=ActiveCell, LookIn:= _

        xlFormulas, LookAt:=xlPart, SearchOrder:=xlByRows, SearchDirection:= _

        xlNext, MatchCase:=False).Activate

 

(Attached screenshot is what the data looks like prior to running the macro. The macro is supposed to remove punctuation, remove certain phrases etc.)

 

Can any of you smart people tell me what's wrong? I don't understand VBA code at all - this macro was created by recording me doing all this stuff manually - but I'm good at following directions :)

 

For what it's worth, here is the entire macro code from start to finish:

Sub step1_amazon_keywordprocessing()

'

' step1_amazon_keywordprocessing Macro

' Change to lower_Use data text to columns to get rid of : and (_get rid of Visit Amazon's_Get rid of page

'

' Keyboard Shortcut: Option+Cmd+r

'

    Range("B1").Select

    ActiveCell.FormulaR1C1 = "=LOWER(RC[-1])"

    Range("B1").Select

    Selection.AutoFill Destination:=Range("B1:B201"), Type:=xlFillDefault

    Range("B1:B201").Select

    Columns("B:B").Select

    Selection.Copy

    Columns("C:C").Select

    Selection.PasteSpecial Paste:=xlValues, Operation:=xlNone, SkipBlanks:= _

        False, Transpose:=False

    Columns("B:B").Select

    Application.CutCopyMode = False

    Selection.ClearContents

    Columns("A:A").Select

    Selection.ClearContents

    Range("C1").Select

    Selection.Copy

    Columns("A:A").Select

    Columns("C:C").Select

    Application.CutCopyMode = False

    Selection.Copy

    Columns("A:A").Select

    ActiveSheet.Paste

    Columns("C:C").Select

    Application.CutCopyMode = False

    Selection.ClearContents

    Columns("A:A").Select

    Selection.TextToColumns Destination:=Range("A1"), DataType:=xlDelimited, _

        TextQualifier:=xlDoubleQuote, ConsecutiveDelimiter:=False, Tab:=True, _

        Semicolon:=False, Comma:=False, Space:=False, Other:=True, OtherChar _

        :=":", FieldInfo:=Array(Array(1, 1), Array(2, 1))

    Columns("B:H").Select

    Selection.ClearContents

    Columns("A:A").Select

    Selection.TextToColumns Destination:=Range("A1"), DataType:=xlDelimited, _

        TextQualifier:=xlDoubleQuote, ConsecutiveDelimiter:=False, Tab:=True, _

        Semicolon:=False, Comma:=False, Space:=False, Other:=True, OtherChar _

        :="(", FieldInfo:=Array(1, 1)

    Columns("B:H").Select

    Selection.ClearContents

    Columns("A:A").Select

    Selection.Find(What:="visit amazon's ", After:=ActiveCell, LookIn:= _

        xlFormulas, LookAt:=xlPart, SearchOrder:=xlByRows, SearchDirection:= _

        xlNext, MatchCase:=False).Activate

    ExecuteExcel4Macro _

        "FORMULA.REPLACE(""visit amazon's "","""",2,1,FALSE,FALSE,,FALSE,FALSE,FALSE,FALSE)"

    Selection.Find(What:=" page", After:=ActiveCell, LookIn:=xlFormulas, _

        LookAt:=xlPart, SearchOrder:=xlByRows, SearchDirection:=xlNext, _

        MatchCase:=False).Activate

    ExecuteExcel4Macro _

        "FORMULA.REPLACE("" page"","""",2,1,FALSE,FALSE,,FALSE,FALSE,FALSE,FALSE)"

End Sub


Thank-you in advance to anyone who can help me with this - I really appreciate it! :)

 

12 Replies

That code will definitely fail. You're using the Selection object to find something after the ActiveCell. If nothing is found, an error is thrown. Overall it's very messy code. The macro recorder makes sure of that. But, it does make a great starting place!

It looks like you took some repetitive actions in the recorded code. I'm not 100% that I followed everything, but I removed all of the Select methods you called, which aren't needed at all. Also, there is no worksheet referenced for the ranges, so it will ALWAYS run on the ActiveSheet. If you are always going to run this code on this worksheet, then it won't be a problem.

Here is the code:

 

Sub step1_amazon_keywordprocessing()
'
' step1_amazon_keywordprocessing Macro
' Change to lower_Use data text to columns to get rid of : and (_get rid of Visit Amazon's_Get rid of page
'
' Keyboard Shortcut: Option+Cmd+r
'
Range("B1:B201").FormulaR1C1 = "=LOWER(RC[-1])"
Columns("B:B").Copy
Columns("C:C").PasteSpecial Paste:=xlValues
Application.CutCopyMode = False
Columns("A:B").ClearContents

Columns("C:C").Copy Columns("A:A")
Columns("C:C").ClearContents
Application.CutCopyMode = False

Columns("A:A").TextToColumns Destination:=Range("A1"), DataType:=xlDelimited, _
TextQualifier:=xlDoubleQuote, ConsecutiveDelimiter:=False, Tab:=True, _
Semicolon:=False, Comma:=False, Space:=False, Other:=True, OtherChar _
:=":", FieldInfo:=Array(Array(1, 1), Array(2, 1))

Columns("B:H").ClearContents

Columns("A:A").TextToColumns Destination:=Range("A1"), DataType:=xlDelimited, _
TextQualifier:=xlDoubleQuote, ConsecutiveDelimiter:=False, Tab:=True, _
Semicolon:=False, Comma:=False, Space:=False, Other:=True, OtherChar _
:="(", FieldInfo:=Array(1, 1)

Columns("B:H").ClearContents

Columns("A:A").Find(What:="visit amazon's ", After:=ActiveCell, LookIn:= _
xlFormulas, LookAt:=xlPart, SearchOrder:=xlByRows, SearchDirection:= _
xlNext, MatchCase:=False).Activate

ExecuteExcel4Macro "FORMULA.REPLACE(""visit amazon's "","""",2,1,FALSE,FALSE,,FALSE,FALSE,FALSE,FALSE)"

On Error Resume Next Columns("A:A").Find(What:=" page", After:=Range("A1"), LookIn:=xlFormulas, _ LookAt:=xlPart, SearchOrder:=xlByRows, SearchDirection:=xlNext, _ MatchCase:=False).Activate
On Error Goto 0 ExecuteExcel4Macro "FORMULA.REPLACE("" page"","""",2,1,FALSE,FALSE,,FALSE,FALSE,FALSE,FALSE)" End Sub

I would recommend stepping through your code the first time, until you know it's working right. To do that, just put your cursor anywhere in this routine (to make it the active routine) and the F8 key will step through each line of code. Tapping the F8 key will execute a single line of code at a time. The yellow highlighted line is the one which will run when you press F8.

 

Also, I added bare-minimum error handling to your Find method. This will ensure it doesn't bomb when executing that line. More importantly, I took out the Selection object you used, and replaced ActiveCell with Range("A1").

 

HTH

 

Thank-you SO much for doing that Zack - I can't tell you how much I appreciate you taking the time :) I learned some new things from what you said that will come in handy over the long term. Plus, it was informative to see your cleaner version of the macro code and I intend to study it until I understand what it's doing.

(Writing all the rest of this partly in case someone else comes along who finds this useful...)

I went through the code line by line as you said, and figured out that the recorded code was getting stuck on the part where it had to find "Visit Amazon's " because in this particular set of data, that wasn't on there. Then the same issue would happen when it was supposed to find " page" because that wasn't in this set of data either.

(For non-techies like me who might read this: F8 didn't work on my Mac (maybe it's a Windows-only shortcut?), but using the little button in the VBA editor that looked like a down error pointing to a dot, which said "step into" if I hovered over it, seems to do the same thing as F8 was supposed to do.)

So I saw what you meant when you said "If nothing is found, an error is thrown."

So if I created a test line that DID contain "Visit Amazon's Test Author page", the macro with the messy recorded code ran fine.

But since I don't want to do the work of adding that every time I want to clean up my data with the macro (just in case it doesn't contain that stuff), I added "On Error Resume Next" before each section of the macro that was supposed to find and replace since the stuff it's looking for won't always be found and that's no big deal. 

Now the macro works despite the messy code.

My next job is to play with YOUR code.

AND, by the way, this ""On Error Resume Next" that you added to your cleaner code is seriously a game changer since now I can make the macro also look for symbols and punctuation marks, and replace those with nothing - this is HUGE for me since prior to your response, I couldn't get the macro to do that for me (which I now understand is because it would get stuck if the thing it was looking for wasn't present). WAHOO! This new knowledge will save me loads of tedious, repetitive manual fixing up in future since now I can make a macro do it all FOR me without getting itself stuck. THANK-YOU SO MUCH!!! 

re: "Also, there is no worksheet referenced for the ranges, so it will ALWAYS run on the ActiveSheet."

Yes, this is okay for my purposes - but thanks for pointing that out!

I'm going to go play with the code more now. This non-techie is so flipping happy with this you have no idea :D


Very happy to help! :)

 

I'm not sure about Mac, but I don't think they have the F-keys on their keyboards and it's typically a PC thing. I use the VBE (Visual Basic Editor) keyboard shortcuts all the time. Huge time savers.

 

I wasn't sure what your Excel4Macro was supposed to be doing, but if it's just replacing values, you can do that in one fell swoop too:

 

RangeToWorkWith.Replace What:="This", Replacement:="That", LookAt:=xlPart

The benefit for this is, not only is it taking care of two lines in one fell swoop, but it won't throw an error like the Find method will, so no need to wrap it in error handling.

 

As long as we're talking about error handling, it should be noted this is the least preferred method for handling errors. The first is to take logical action in your code to prevent known errors from forming. The next would be trapping errors - performing some kind of check if an error was processed, like "If Err.Number <> 0".

 

Thanks for the detailed response. Have a great day!

 

re: "I wasn't sure what your Excel4Macro was supposed to be doing"

Ha, neither am I! That's what you get when non-technie uses "record macro" lol

re: "
if it's just replacing values, you can do that in one fell swoop too:

 

RangeToWorkWith.Replace What:="This", Replacement:="That", LookAt:=xlPart

The benefit for this is, not only is it taking care of two lines in one fell swoop, but it won't throw an error like the Find method will, so no need to wrap it in error handling.

Ahh, cool. I'm going to play with that - because yes, it's nothing more than replacing values.

For syntax, say I wanted it to replace all "!" in column A with "" (i.e. erase the ! and replace it with nothing), and then replace all "-" in column A with " " (i.e. replace a dash with a single space)... how would I write that using that type of code? I can guess all sorts of potential ways to "fill in the blanks", but don't know which one is correct... for the exclamation mark, for example...

Option 1:

 

RangeToWorkWith.Replace What:="!", Replacement:="", LookAt:=A

 

Option 2

A.Replace What:="!", Replacement:="", LookAt:=A

Option 3:

Range(A1).Replace What:="!", Replacement:="", LookAt:=A1

Something else? 

Sorry... I realize this must be insanely basic to you since you know what you're doing hehe  And if you're tired of answering questions, that's cool too - the information you've already provided has been very helpful!

Really close! The 'RangeToWorkWith' is a Range object variable. So it can be any Range. For example...

Range("A1")

...or...


Dim RangeToWorkWith As Range
Set RangeToWorkWith = Range("A1")

 

In the latter, 'RangeToWorkWith' is now the same as Range("A1"). The benefit of a variable is you can set it to whatever you want, and most importantly make them dynamic.

 

The "LookAt" parameter of the Find or Replace method should be either xlPart or xlWhole, both part of the 'XlLookAt' class of constants (which may be a little above your head at this point, but that's ok - immersion!). This says whether you want to look at the entire contents of the cell for the What parameter. In your case it should be xlPart.

 

So, let's say you want to do all of this in column A. For me, I don't want to look at the whole column, because that's a LOT of cells, and I'm probably using a fraction of them. Also, let's say we have a header in row 1. So data starts on row 2 and goes down an unknown number of rows. This is called a dynamic range, because it may not always be the same size, and is why a recorded macro may not work so well as it hard-codes the range address into the Range object.

 

Dim ReplaceSheet As Worksheet
Dim ReplaceRange As Range

Set ReplaceSheet = ThisWorkbook.Worksheets("Sheet1")
Set ReplaceRange = ReplaceSheet.Range("A2", ReplaceSheet.Cells(ReplaceSheet.Rows.Count, "A").End(xlUp))

ReplaceRange.Replace What:="!", Replacement:="", LookAt:=xlPart
ReplaceRange.Replace What:="-", Replacement:=" ", LookAt:=xlPart

With the above code, it doesn't matter if your data is in A2:A10, or A2:A1000, it will work on that data range. It basically looks at the bottom-most cell in that column and goes up until it finds data (the keyboard shortcut equivalent is, from the bottom of the sheet, press CTRL + Up Arrow).  Then it uses that range with the Replace method.

 

Another added benefit of using a variable (properly scoped) is you get intellisense on that object. Since I declared the variable of a Range type, when you type that variable name and press period, you see a drop-down list of all methods and properties associated with that object. Methods have the little green icon, properties have the little card with a hand on it. Methods do something, and may or may not take parameters passed to it (we're passing three parameters in the above code). Properties let us read (and sometimes write) data to that property. A property can be values (i.e. text, numbers, dates) or objects (i.e. Range, Shape, Worksheet, Workbook). And hence commenses your crash course into Object Oriented Programming (OOP)! :)

 

I don't mind answering any question you might have. Post away!

You're amazing for explaining all that - thank-you so much! I'm going to try it :D

Okay, I'm back :D

So this is what I tried to create based on the above info, previous posts you've shared, and some Googling:

(What I want it to do is to find and replace certain characters and words I don't want, but to ONLY do this on the sheet I'm currently looking at. And if it doesn't find the character it just looked for (will happen often), I want it to skip ahead to the next one listed in the code.)

Sub Sher_step2_amazon_keywordprocessing_find_and_replace_stuff()
'
' Sher_step2_amazon_keywordprocessing_find_and_replace_stuff Macro

' Change to lower_find and replace prohibited symbols and words
'
Dim ReplaceSheet As Worksheet
Dim ReplaceRange As Range

Set ReplaceSheet = ThisWorkbook.Worksheets("Sheet1")
Set ReplaceRange = ReplaceSheet.Range("A2", ReplaceSheet.Cells(ReplaceSheet.Rows.Count, "A").End(xlUp))

ReplaceRange.Replace What:="!", Replacement:="", LookAt:=xlPart
On Error Resume Next

ReplaceRange.Replace What:="@", Replacement:="at", LookAt:=xlPart
On Error Resume Next

ReplaceRange.Replace What:="#", Replacement:="", LookAt:=xlPart
On Error Resume Next

ReplaceRange.Replace What:="$", Replacement:="", LookAt:=xlPart
On Error Resume Next

ReplaceRange.Replace What:="%", Replacement:="percent", LookAt:=xlPart
On Error Resume Next

ReplaceRange.Replace What:="^", Replacement:="", LookAt:=xlPart
On Error Resume Next

ReplaceRange.Replace What:="&", Replacement:="and", LookAt:=xlPart
On Error Resume Next

ReplaceRange.Replace What:="<", Replacement:="", LookAt:=xlPart
On Error Resume Next

ReplaceRange.Replace What:=">", Replacement:="", LookAt:=xlPart
On Error Resume Next

ReplaceRange.Replace What:="- ", Replacement:=" ", LookAt:=xlPart
On Error Resume Next

ReplaceRange.Replace What:="-", Replacement:=" ", LookAt:=xlPart
On Error Resume Next

ReplaceRange.Replace What:="  ", Replacement:=" ", LookAt:=xlPart
On Error Resume Next

ReplaceRange.Replace What:=". ", Replacement:="", LookAt:=xlPart
On Error Resume Next

ReplaceRange.Replace What:=".", Replacement:="", LookAt:=xlPart
On Error Resume Next

ReplaceRange.Replace What:="  ", Replacement:=" ", LookAt:=xlPart
On Error Resume Next

ReplaceRange.Replace What:="/", Replacement:=" ", LookAt:=xlPart
On Error Resume Next

ReplaceRange.Replace What:=",", Replacement:="", LookAt:=xlPart
On Error Resume Next

ReplaceRange.Replace What:="“", Replacement:="", LookAt:=xlPart
On Error Resume Next

ReplaceRange.Replace What:="“", Replacement:="", LookAt:=xlPart
On Error Resume Next

ReplaceRange.Replace What:="”", Replacement:="", LookAt:=xlPart
On Error Resume Next

ReplaceRange.Replace What:="—", Replacement:=" ", LookAt:=xlPart
On Error Resume Next

ReplaceRange.Replace What:="®", Replacement:="", LookAt:=xlPart
On Error Resume Next

ReplaceRange.Replace What:="Kindle", Replacement:="", LookAt:=xlPart
On Error Resume Next

End Sub

But I got stumped on the following:

1. As written, the macro appears to do it's thing only on a sheet of my workbook called "Sheet1" (which I don't want it to do). What I DO want is for it to do its thing only on whatever sheet I'm currently working on regardless of the name. (Not all sheets in the workbook though... only the one sheet I'm looking at). :)

If I delete the line of code that references "sheet1", I get an error when I try to run the macro. If I cave and decide that fine, I'll tell it to run on a specific sheet, and I replace "sheet1" with the name of the sheet I want it to run on right now (ExperimentWithNewMacro), I get a runtime error (Runtime error 9. Subscript out of range.) - if I click on "Debug", it highlights this row of code:

Set ReplaceSheet = ThisWorkbook.Worksheets("ExperimentWithNewMacro")

I tried fiddling around with it, Googling, tweaking things etc... but couldn't get it to work. I figure I must be missing something, and I'm crossing my fingers that it'll be quick and obvious for you to see where I went wrong :)


Okay, awesome news! Thanks to all your help Zack, I got the second macro to do what I want it to! Holy cow - this is beyond amazing since it will save me HOURS of repetitive manual labour replacing symbols and prohibited words with spaces or flat-out nothing.

I thought I'd posted another questions about how I got stuck, but I don't see it here. I kept playing around with the problem and managed to fix it despite being clueless haha So if that new question from today DOES show up, you can ignore it.

Thanks again!!! :D

That's awesome! We do love saving people time. ;)

Very much appreciate the follow-up. It helps us know that what we do is worth it.

Hey guys,

 

I am trying to fill-in data in a website with VBA, but I am getting a run time error 91. I have the idea that there is an error due to auto-complete, but I am not 100% sure.

The website is to calculate travel time, the value is (Dutch) travel data.

 

Who can help me?  

@Zack Barresse?

VBA Code:

--------------------------------------------------------------------------------------

 

Sub GetHTMLDocument()

Dim IE As New SHDocVw.InternetExplorer
Dim HTMLDoc As MSHTML.HTMLDocument
Dim HTMLInput As MSHTML.IHTMLElement
Dim HTMLButtons As MSHTML.IHTMLElementCollection
Dim HTMLButton As MSHTML.IHTMLElement

IE.Visible = True
IE.navigate "https://www.anwb.nl/verkeer/routeplanner"

Do While IE.ReadyState <> READYSTATE_COMPLETE
Loop

Set HTMLDoc = IE.Document
Set HTMLInput = HTMLDoc.getElementById("routing-input-address-field-0")
HTMLInput.Value = "9711NA"


End Sub

-----------------------------------------------------------------------------------

@Gijs1 please start your own thread. Feel free to message me the link. Also, your code looks fine and you shouldn't be getting that error. You would, however, need two references (Tools > References...) Microsoft HTML Object Library and Microsoft Internet Controls.

Just leaving this response here in case someone finds this useful. I was facing a similar issue when running a macro. I was trying to run the macro on a recently downloaded file and it kept throwing the Runtime Error 91. Enabling Editing (clicking on Enable Editing) fixed the issue for me. 

Related Conversations
How to Prevent Teams from Auto-Launch
chenrylee in Microsoft Teams on
28 Replies
Tabs and Dark Mode
cjc2112 in Discussions on
2 Replies
Early preview of Microsoft Edge group policies
Sean Lyndersay in Discussions on
65 Replies
*Updated 9/3* Syncing in Microsoft Edge Preview Channels
Elliot Kirk in Articles on
202 Replies