Excel format selected column Topic is solved

Get help with using AutoHotkey (v1.1 and older) and its commands and hotkeys
monicakes123
Posts: 6
Joined: 17 Jun 2022, 10:13

Excel format selected column

Post by monicakes123 » 30 Jun 2022, 09:13

Hi!

I am trying to format all the cells in the selected column. I got the below code to format for the selected cell.

Thank you!

Code: Select all

#NoEnv  ; Recommended for performance and compatibility with future AutoHotkey releases.
; #Warn  ; Enable warnings to assist with detecting common errors.
SendMode Input  ; Recommended for new scripts due to its superior speed and reliability.
SetWorkingDir %A_ScriptDir%  ; Ensures a consistent starting directory.

f3::
oExcel := ComObjActive("Excel.Application")

dash := "-"
space_ := " "
blank_ := ""

Active_cell := oExcel.activecell
Active_cell.replace(dash, blank_)
Active_cell.replace(space_, blank_)
oExcel.activecell.NumberFormat := "000-0000 0000"


return

User avatar
flyingDman
Posts: 2817
Joined: 29 Sep 2013, 19:01

Re: Excel format selected column  Topic is solved

Post by flyingDman » 30 Jun 2022, 10:25

Try:

Code: Select all

dash := "-"
space_ := " "
blank_ := ""

xl := ComObjActive("excel.application")
rng := xl.intersect(xl.activecell.EntireColumn, xl.activesheet.usedrange)
for c in rng
	{
	c.replace(dash, blank_)
	c.replace(space_, blank_)
	c.NumberFormat := "000-0000 0000"
	}
14.3 & 1.3.7

monicakes123
Posts: 6
Joined: 17 Jun 2022, 10:13

Re: Excel format selected column

Post by monicakes123 » 30 Jun 2022, 10:40

@flyingDman Thank you!!

Post Reply

Return to “Ask for Help (v1)”