vba - Force no empty cell depending on another cell in Excel -


is possible in excel force no empty cell depending on cell? mean if type in e.g. casenumber in a1, have type in in b1 , c1 also. , should dynamic, should work on cells in column b , c, should @ cell in same row in column a.

just more details....

because original sheets isn't designed exported, need copy appropiate data sheet before exporting.

so have ungly sheets filled out cell copy nicer layout on sheet, in turn export csv.

i use code copy data:

private sub copyallnonblanksinrange() sheets("flexhal tilbudsregistrering") .columns("e").specialcells(xlcelltypeconstants).copy destination:=sheets("ark1").range("a1") .columns("f").specialcells(xlcelltypeconstants).copy destination:=sheets("ark1").range("b1") .columns("g").specialcells(xlcelltypeconstants).copy destination:=sheets("ark1").range("c1") end end sub

so problem in copy process, as should copies cells contains data.

at point can see have run through row check if filled out , copy based on that. seems mess, , i'm not sure of how that.

this can accomplished event macro macro enforce scenario:

  1. start all cells protected except a1
  2. once user has filled a1, both b1 , c1 become un-protected
  3. once user has filled both b1 , c1, a2 become un-protected

etc.

edit#1

first enter , run macro setup sheet:

sub setupp()     activesheet.unprotect     application.enableevents = false     cells.clear     cells.locked = false         range("a1")             .select             cells.locked = true             .locked = false         end     activesheet.protect     application.enableevents = true end sub 

then enter event macro in worksheet code area:

private sub worksheet_change(byval target range) dim range, n long set = range("a:a") n = target.row if not intersect(target, a) nothing     activesheet.unprotect         target.offset(0, 1).select         cells.locked = true         range("b" & n & ":c" & n).locked = false     activesheet.protect else     if application.worksheetfunction.counta(range("b" & n & ":c" & n)) = 2         activesheet.unprotect             range("a" & n + 1).select             cells.locked = true             range("a" & n + 1).locked = false         activesheet.protect     end if end if end sub 

because worksheet code, easy install , automatic use:

  1. right-click tab name near bottom of excel window
  2. select view code - brings vbe window
  3. paste stuff in , close vbe window

if have concerns, first try on trial worksheet.

if save workbook, macro saved it. if using version of excel later 2003, must save file .xlsm rather .xlsx

to remove macro:

  1. bring vbe windows above
  2. clear code out
  3. close vbe window

to learn more macros in general, see:

http://www.mvps.org/dmcritchie/excel/getstarted.htm

and

http://msdn.microsoft.com/en-us/library/ee814735(v=office.14).aspx

to learn more event macros (worksheet code), see:

http://www.mvps.org/dmcritchie/excel/event.htm

macros must enabled work!


Comments

Popular posts from this blog

javascript - RequestAnimationFrame not working when exiting fullscreen switching space on Safari -

Python ctypes access violation with const pointer arguments -